Computer Science Canada Integer.parseInt throws format exception, what to do? |
Author: | Justin_ [ Wed Apr 26, 2006 2:13 pm ] | ||||||
Post subject: | Integer.parseInt throws format exception, what to do? | ||||||
I'm getting a numberFormatExcetion from this code that reads integers from a textfile. The textfile has a new integer on each line, so if you made a textfile for example like this:
That would be what you need to run the program and call it IntegerData.txt. Here's the exact error:
|
Author: | HellblazerX [ Wed Apr 26, 2006 2:29 pm ] | ||||||
Post subject: | |||||||
your gonna have to replace that do while loop with a while loop, because what your program is doing is reading 1 more line than what your file actually has. so, on your line:
replace that with this:
also theres another problem i noticed with this line:
you shouldn't have have that <= sign, but rather just a < sign, otherwise you'll be calling on a non existing element. You have to remember that arrays start at 0, so an array with a size of 3 will go 0,1,2. |
Author: | Justin_ [ Thu Apr 27, 2006 5:00 pm ] |
Post subject: | |
Thanks Hellblazer |