
-----------------------------------
Justin_
Wed Apr 26, 2006 2:13 pm

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: 

1
2
3

That would be what you need to run the program and call it IntegerData.txt.

Here's the exact error:

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 Sort.sortIt(MooserBubbleSort.java:31)
        at MooserBubbleSort.main(MooserBubbleSort.java:9)




import java.io.*;
import java.util.*;

public class MooserBubbleSort
{
	public static void main(String args

-----------------------------------
HellblazerX
Wed Apr 26, 2006 2:29 pm


-----------------------------------
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:
do
            {
                    stringNumber = input.readLine();
                    number = Integer.parseInt(stringNumber);
                    addNumberToArray(number);
              }  while (stringNumber != null);

replace that with this:
stringNumber = input.readLine ();
        while (stringNumber != null)
        {
            number = Integer.parseInt (stringNumber);
            addNumberToArray (number);
            stringNumber = input.readLine ();
        }
also theres another problem i noticed with this line:
for (int i = 0; i 