• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

NumberFormatException: null

 
Greenhorn
Posts: 4
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I'm trying to write a program to perform some of the some of the functionality of StringTokenizer for an assignment, my instructor provides the driver and I do the rest. I've gone about as far as I can but I keep hitting a "NumberFormatException: null" run time error when trying to run the driver. I did some digging around and it looks like it's a result of my trying to parse a null value, but I've been banging my head on my desk trying to figure out how to fix it. Here's my code:

Driver (provided):


Here's my program (original):


Here's the text file it's reading:

1111,f,Anna,Arcello,10,1.01,1040,Suspension
2222,f,Barbara,Brew,20,2.02,1041
3333,f,Cindy,Crawford,30,3.03,1042
4444,f,Debbie,Desoni,40,1.40,1043,Probation
5555,m,Ed,Evans,50,2.50,1045
6666,f,Fonda,Farley,60,3.60,1040
7777,m,George,Goodin,70,1.07,1041,Probation
8888,f,Hedi,Hust,80,2.08,1042
9999,m,Ivan,Ingraham,90,3.09,1044



Here's the error I'm getting:

---------- Capture Output ----------
> "F:\Program Files\Java\jdk1.6.0_07\bin\java.exe" Meo04tokenizerDvr

Rec Tok Ct ID Name Hrs GPA Major Gender Status
--- ------ ---- ----------------- --- ---- ----- ------ ----------
1 8 1111 Arcello, Anna 10 1.01 1040 Female Suspension
Exception in thread "main" java.lang.NumberFormatException: null
at java.lang.Integer.parseInt(Integer.java:415)
at java.lang.Integer.parseInt(Integer.java:497)
at Meo04tokenizer.getIntTok(Meo04tokenizer.java:45)
at Meo04tokenizerDvr.main(Meo04tokenizerDvr.java:46)
> Terminated with exit code 1.



I'd really appreciate any help you guys can give me.
 
Java Cowboy
Posts: 16084
88
Android Scala IntelliJ IDE Spring Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Look carefully at the stack trace. Especially this line:

at Meo04tokenizer.getIntTok(Meo04tokenizer.java:45)


It tells you exactly where in your source code the error happened.

In that line of code, you are parsing an object into a number, but the thing you are trying to parse is null. That's not a valid input for Double.parseDouble(...), so you get a NumberFormatException. Lookup the method Double.parseDouble(...) in the Java API documentation.
 
Ranch Hand
Posts: 230
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
The problem is the huge list of tokens that you place each line in that I think is muddling up your ability to debug. We could have a reasonable discussion about they way this is being done but the long and short of your problem is when you create the constructor for the tokenizer the indexes for the list should begin anew. Since your list object isn't static it's being recreated every time you create the object so you aren't keeping every line in there anyway. Since the indexes are static among each one of those objects you keep the indexes you were at before but you don't even have the old line there.



At the beginning of your Meo04tokenizer constructor should fix your issue.
 
S. Shin
Greenhorn
Posts: 4
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Paul Yule wrote:The problem is the huge list of tokens that you place each line in that I think is muddling up your ability to debug. We could have a reasonable discussion about they way this is being done but the long and short of your problem is when you create the constructor for the tokenizer the indexes for the list should begin anew. Since your list object isn't static it's being recreated every time you create the object so you aren't keeping every line in there anyway. Since the indexes are static among each one of those objects you keep the indexes you were at before but you don't even have the old line there.



At the beginning of your Meo04tokenizer constructor should fix your issue.




Worked perfect, thanks a ton! I'll look over the way things are laid out and try to make them a bit more efficient.
 
Paul Yule
Ranch Hand
Posts: 230
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Glad to help.
 
I promise I will be the best, most loyal friend ever! All for this tiny ad:
a bit of art, as a gift, that will fit in a stocking
https://gardener-gift.com
reply
    Bookmark Topic Watch Topic
  • New Topic