-4

I am using the Netbeans IDE for my code. I am getting this error when I try to run it:"

Exception in thread "main" java.lang.NumberFormatException: For input string: "8589.416,5468.2407,4263.4077,4064.9358,1997.893,5282.325,2169.72,2773.4211,7526.386,4607.6763,2598.06,1522.6462,1300.5988,1181.63,Tumor"
    at sun.misc.FloatingDecimal.readJavaFormatString(FloatingDecimal.java:1250)
    at java.lang.Double.parseDouble(Double.java:540)
    at Preprocessing.Newsvm_scale.run(Newsvm_scale.java.java:150)
    at Preprocessing.Newsvm_scale.main(Newsvm_scale.java.java:332)

I keep in mind that the other similar questions here couldn't helped me since I have a different code. My code is below. If anyone can point me in the right direction I will be incredibly grateful. Thanks.

ahmed
  • 13
  • 6
  • 1
    Debug your code, go to line 540 and take a look at the parameter of ``Double.parseDouble``. It's a huge string, not a single number. That cannot be parsed to a ``Double``. – f1sh Feb 09 '17 at 10:54
  • 1
    I don't think `8589.416,5468.2407,4263.4077,4064.9358,1997.893,5282.325,2169.72,2773.4211,7526.386,4607.6763,2598.06,1522.6462,1300.5988,1181.63,Tumor` is a number either. – Salem Feb 09 '17 at 10:55
  • 4
    Did you read the error message? It includes the actual string that you were trying to parse, and it *clearly* is not a valid decimal number. – Stephen C Feb 09 '17 at 10:55
  • And please, see [ask]. And more important, provide a [mcve]. There is way to many code here.. – AxelH Feb 09 '17 at 11:29

1 Answers1

0

The StringTokenizer method has set one long string to the value st, which is not being broken up. So when the Double Parse method is being called. It throws a Number format exception, because it is trying to convert that string to a double. You need to specify that commas separate the numbers when calling the StringTokenizer method. Feel free to ask if you like some more assistance.

JordanH
  • 190
  • 5
  • ...or you could add to your answer. – Salem Feb 09 '17 at 12:50
  • Thanks a lot@jordanH. yes the file that I used is commas separate delimited. but I could not understand you, what do you mean by (you need to specify that commas separate the numbers). can you explain more? thank you – ahmed Feb 09 '17 at 13:07
  • When you instantiate the StringTokenizer object you should specify the character that is used to seperate the tokens. In this case the tokens are seperated by commas. Here is an example: http://stackoverflow.com/questions/9446704/using-multiple-delimiters-with-stringtokenizer StringTokenizer str = new StringTokenizer(stringName, ","); where the comma signifies the delimiter. – JordanH Feb 09 '17 at 13:18
  • I try to do as you suggest me@JordanH ( StringTokenizer st = new StringTokenizer(line," ,");) . But still faced the same error – ahmed Feb 09 '17 at 16:38