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:
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.
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.
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
posted
0
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
posted
0
Glad to help.
I agree. Here's the link: http://ej-technologies/jprofiler - if it wasn't for jprofiler, we would need to
run our stuff on 16 servers instead of 3.