aspose file tools*
The moose likes Beginning Java and the fly likes NumberFormatException: null Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Beginning Java
Bookmark "NumberFormatException: null" Watch "NumberFormatException: null" New topic
Author

NumberFormatException: null

S. Shin
Greenhorn

Joined: Apr 02, 2009
Posts: 4
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.
Jesper de Jong
Java Cowboy
Saloon Keeper

Joined: Aug 16, 2005
Posts: 14435
    
  23

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.


Java Beginners FAQ - JavaRanch SCJP FAQ - The Java Tutorial - Java SE 8 API documentation
Paul Yule
Ranch Hand

Joined: May 12, 2008
Posts: 229
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

Joined: Apr 02, 2009
Posts: 4
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

Joined: May 12, 2008
Posts: 229
Glad to help.
 
wood burning stoves
 
subject: NumberFormatException: null