Connecting Tech Pros Worldwide Forums | Help | Site Map

Converting String to Double Problem

Newbie
 
Join Date: Oct 2006
Posts: 9
#1: Oct 18 '06
Hi,

I have retrieved values in a file. Used

Double dval;
String line;
try{

BufferedReader in=new BufferedReader(new FileReader("File1.txt"));
line = in.readLine();
dval=Double.parseDouble(line);
System.out.println(dval);
}
catch(IOException e){}
catch(NumberFormatException e){}

.
.
.
.


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

Newbie
 
Join Date: Oct 2006
Posts: 3
#2: Oct 18 '06

re: Converting String to Double Problem


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.
Newbie
 
Join Date: Oct 2006
Location: NH
Posts: 3
#3: Oct 18 '06

re: Converting String to Double Problem


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
Lives Here
 
Join Date: Sep 2006
Posts: 12,070
#4: Oct 18 '06

re: Converting String to Double Problem


Quote:

Originally Posted by Asad

Hi,

I have retrieved values in a file. Used

Double dval;
String line;
try{

BufferedReader in=new BufferedReader(new FileReader("File1.txt"));
line = in.readLine();
dval=Double.parseDouble(line);
System.out.println(dval);
}
catch(IOException e){}
catch(NumberFormatException 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.
Newbie
 
Join Date: Oct 2006
Posts: 9
#5: Oct 19 '06

re: Converting String to Double Problem


Quote:

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.parseInt(line); or Double.parseDouble(line);
please help.
Lives Here
 
Join Date: Sep 2006
Posts: 12,070
#6: Oct 20 '06

re: Converting String to Double Problem


Quote:

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.parseInt(line); or Double.parseDouble(line);
please help.

change
catch(IOException e){}
catch(NumberFormatException e){}
to
Expand|Select|Wrap|Line Numbers
  1. catch(IOException e){
  2.  e.printStackTrace();
  3. }
  4. catch(NumberFormatException e){
  5.  e.printStackTrace();
  6. }
compile and run and see what happens
Reply