Converting String to Double Problem

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • Asad
    New Member
    • Oct 2006
    • 9

    #1

    Converting String to Double Problem

    Hi,

    I have retrieved values in a file. Used

    Double dval;
    String line;
    try{

    BufferedReader in=new BufferedReader( new FileReader("Fil e1.txt"));
    line = in.readLine();
    dval=Double.par seDouble(line);
    System.out.prin tln(dval);
    }
    catch(IOExcepti on e){}
    catch(NumberFor matException e){}

    .
    .
    .
    .


    Well, I am not getting any errors, Yet dval is not being printed. Please Help me!!
  • Prasanth Nair
    New Member
    • Oct 2006
    • 3

    #2
    looks like your application is not reading the file.Try giving some SOP in the catch block & give a printstack tace there. You might be able to see the error.

    Comment

    • stevehnsn
      New Member
      • Oct 2006
      • 3

      #3
      For situations such as this you have to make good use of debugging. This means printing various values out to the console to check their validity. You should definitely be using some sort of logging or printing to standard output in all of your error handling from now on. The sooner you can start implementing proper coding practices, the better you will be in the long run.

      Good luck!

      Steve Hanson
      Tasen Software
      New Hampshire (NH) Website Design and Software Development

      Comment

      • r035198x
        MVP
        • Sep 2006
        • 13225

        #4
        Originally posted by Asad
        Hi,

        I have retrieved values in a file. Used

        Double dval;
        String line;
        try{

        BufferedReader in=new BufferedReader( new FileReader("Fil e1.txt"));
        line = in.readLine();
        dval=Double.par seDouble(line);
        System.out.prin tln(dval);
        }
        catch(IOExcepti on e){}
        catch(NumberFor matException e){}

        .
        .
        .
        .


        Well, I am not getting any errors, Yet dval is not being printed. Please Help me!!
        That is not exception handling. That is exception hiding.

        Comment

        • Asad
          New Member
          • Oct 2006
          • 9

          #5
          Originally posted by r035198x
          That is not exception handling. That is exception hiding.

          Well, Could you please tell me whats wrong with my program. I do have the file and its reading from the file too, yet I am unable to convert it to double or any other format using parse, like Integer.parseIn t(line); or Double.parseDou ble(line);
          please help.

          Comment

          • r035198x
            MVP
            • Sep 2006
            • 13225

            #6
            Originally posted by Asad
            Well, Could you please tell me whats wrong with my program. I do have the file and its reading from the file too, yet I am unable to convert it to double or any other format using parse, like Integer.parseIn t(line); or Double.parseDou ble(line);
            please help.
            change
            catch(IOExcepti on e){}
            catch(NumberFor matException e){}
            to
            Code:
            catch(IOException e){
             e.printStackTrace();
            }
            catch(NumberFormatException e){
             e.printStackTrace();
            }
            compile and run and see what happens

            Comment

            Working...