Problem with StringTokenizer and String.split()

I have this class for a golf game I'm writing:

import java.io.*;

import java.util.StringTokenizer;

publicclass CourseListReader

{

publicstatic Course[] getCourseList()

{

try

{

BufferedReader courseReader =new BufferedReader(new FileReader("courses\\courses.dat"));

Course[] courses =new Course[20];

for (int i = 0; i < courses.length; i++)

{

String courseLine = courseReader.readLine();

StringTokenizer st =new StringTokenizer(courseLine,":");

Course thisCourse =new Course();

thisCourse.name = removeQuotes(st.nextToken());

thisCourse.directory = removeQuotes(st.nextToken());

courses[i] = thisCourse;

}

return courses;

}

catch (IOException ioe)

{

ioe.printStackTrace();

returnnull;

}

}

publicstatic String removeQuotes(String input)

{

StringBuffer output =new StringBuffer();

char[] characters = input.toCharArray();

for (int i = 0; i < characters.length; i++)

{

char currentChar = characters[i];

if (currentChar !='\"' && currentChar !='\'')

{

output.append(currentChar);

}

}

return output.toString();

}

}

class Course

{

String name;

String directory;

}

However, when I call getCourseList(), I get this exception:

Exception in thread"AWT-EventQueue-0" java.lang.NullPointerException

at java.util.StringTokenizer.<init>(Unknown Source)

at java.util.StringTokenizer.<init>(Unknown Source)

at CourseListReader.getCourseList(CourseListReader.java:17)

at GolfGameCourseChooserPanel.<init>(GolfGameCourseChooserPanel.java:8)

at GolfGameWaitingPanel.actionPerformed(GolfGameWaitingPanel.java:76)

at javax.swing.AbstractButton.fireActionPerformed(Unknown Source)

at javax.swing.AbstractButton$Handler.actionPerformed(Unknown Source)

at javax.swing.DefaultButtonModel.fireActionPerformed(Unknown Source)

at javax.swing.DefaultButtonModel.setPressed(Unknown Source)

at javax.swing.plaf.basic.BasicButtonListener.mouseReleased(Unknown Sour

ce)

at java.awt.Component.processMouseEvent(Unknown Source)

at javax.swing.JComponent.processMouseEvent(Unknown Source)

at java.awt.Component.processEvent(Unknown Source)

at java.awt.Container.processEvent(Unknown Source)

at java.awt.Component.dispatchEventImpl(Unknown Source)

at java.awt.Container.dispatchEventImpl(Unknown Source)

at java.awt.Component.dispatchEvent(Unknown Source)

at java.awt.LightweightDispatcher.retargetMouseEvent(Unknown Source)

at java.awt.LightweightDispatcher.processMouseEvent(Unknown Source)

at java.awt.LightweightDispatcher.dispatchEvent(Unknown Source)

at java.awt.Container.dispatchEventImpl(Unknown Source)

at java.awt.Window.dispatchEventImpl(Unknown Source)

at java.awt.Component.dispatchEvent(Unknown Source)

at java.awt.EventQueue.dispatchEvent(Unknown Source)

at java.awt.EventDispatchThread.pumpOneEventForHierarchy(Unknown Source)

at java.awt.EventDispatchThread.pumpEventsForHierarchy(Unknown Source)

at java.awt.EventDispatchThread.pumpEvents(Unknown Source)

at java.awt.EventDispatchThread.pumpEvents(Unknown Source)

at java.awt.EventDispatchThread.run(Unknown Source)

Using String.split also gives me a NullPointerException.

In case it helps, here's courses\courses.dat:

"Test Course":"testcourse"

It's just a test file, but it should work.

[5246 byte] By [sdhafjasdfa] at [2007-10-1 19:37:20]
# 1
After some excessive debugging statements, I found out that the exception occurs when the StringTokenizer is created.
sdhafjasdfa at 2007-7-11 15:53:17 > top of Java-index,Developer Tools,Debugging and Profiling Tool APIs...
# 2
>String courseLine = courseReader.readLine();Check to see if courseLine is null. Passing a null to StringTokenizer will cause a NullpointerException.
Caffeine0001a at 2007-7-11 15:53:17 > top of Java-index,Developer Tools,Debugging and Profiling Tool APIs...
# 3

Interestingly enough, I did

System.out.println(courseLine)

right after I read the line in and it printed out two lines: one with the actual text in the file and one with the word "null". And then it threw a NullPointerException. (I'm getting ready to go remove that class from my JRE :-) Let me check if putting a new line at the end of the file helps.

sdhafjasdfa at 2007-7-11 15:53:17 > top of Java-index,Developer Tools,Debugging and Profiling Tool APIs...
# 4
No, that didn't help.
sdhafjasdfa at 2007-7-11 15:53:17 > top of Java-index,Developer Tools,Debugging and Profiling Tool APIs...
# 5
Hmmm, interesting. I put everything inside the for loop into a try...catch block, and caught the NPE with a break statement. Now it returns Course@15311bd...?
sdhafjasdfa at 2007-7-11 15:53:17 > top of Java-index,Developer Tools,Debugging and Profiling Tool APIs...
# 6
I've fixed that too -- I was using the entire Course object instead of just the name property in my JList. That must have been its funky way of casting it to a String. I'll give the 10 Duke Dollars to Caffeine.
sdhafjasdfa at 2007-7-11 15:53:17 > top of Java-index,Developer Tools,Debugging and Profiling Tool APIs...