| Author |
NumberFormatException
|
Prasun Howlader
Ranch Hand
Joined: Oct 21, 2007
Posts: 89
|
|
Dear sir, I want to take input from a file and the file value is double. Here is the file graph1 contains- And my Java program is- But when i run this file it throws NumberFormatException.Why this error generate?
|
"Control time instead of letting time control you."
|
 |
Ankit Garg
Saloon Keeper
Joined: Aug 03, 2008
Posts: 9189
|
|
|
I am not sure but I think \\s will not split the contents based on \n. So first split the content on \n and then on \\s. But I am not sure about this...
|
SCJP 6 | SCWCD 5 | Javaranch SCJP FAQ | SCWCD Links
|
 |
Venkata Kumar
Ranch Hand
Joined: Apr 16, 2008
Posts: 110
|
|
When the lines are retrieved from file , space has to be added after each line.
|
SCJP 5.0, SCWCD 5, preparing for SCDJWS
|
 |
Jesper de Jong
Java Cowboy
Bartender
Joined: Aug 16, 2005
Posts: 12928
|
|
This does not sound like it is a question that is about the SCJP exam. Please take the time to carefully choose one forum before you post a question. I'm moving this to a more appropriate forum for you.
|
Java Beginners FAQ - JavaRanch SCJP FAQ - The Java Tutorial - Java SE 7 API documentation
Scala Notes - My blog about Scala
|
 |
Djonatah Stiegler
Ranch Hand
Joined: Oct 30, 2008
Posts: 32
|
|
|
Didn't you get the token with leading spaces?
|
From Brazil
|
 |
Campbell Ritchie
Sheriff
Joined: Oct 13, 2005
Posts: 32689
|
|
Why do you think that using "\\s" as a delimiter will not split the Strings correctly? The details of what "\\s" means are in the Pattern class. Why are you using the old-fashioned way to read from files; the Scanner class is a lot easier? I know many books print lots of code in the main method, but running all that code from the main method and using static fields doesn't look like good object-oriented programming to me. And please use [] rather than ... in the main method declaration. Take a pencil and paper and write down what your String st will look like after the first line, then add the next line to it. Remember the "readLine()" method stops at the line end character. Then when you have seen what it looks like, you will understand why you are getting an Exception. And please give us full details; there is an important hint in the message which goes with the Exception. That is why Djonatah Stiegler saw what was going wrong and asked about spaces. I think using a Scanner and its methods (it has lots of nextXXX methods and hasNextXXX methods, and you are sure to find one to suit your requirements) will make things easier. Have you got the structure of the file right. Shouldn't the 0.00 be x[0] and the 1.00 on the same line be y[0]? In which case your for loop which only counts up to length / 2 will need to be changed. Good luck with it
|
 |
 |
|
|
subject: NumberFormatException
|
|
|