I'm getting a null pointer exception when using a buffered file reader, and I can't seem to figure out why.
Here's the code that's giving me a null pointer exception:
It creates a new Buffered File reader using the File() constructor on a sample file, and tries to split each line of the file on semicolons.
The exception is on line 24, I've tried simply printing out the reader and it is not null, so I'm pretty clueless...
Here is the sample file:
Does anyone have any ideas?
For starters, you should avoid giving your classes names that clash wth class names in the JRE - that's bound to cause confusion and conflicts (java.io.File).
On line 24, two objects could be null - "reader" or "reader.readLine()". It seems that "reader" should not be null -or you would have gotten an exception in line 7- so it would seem that readLine returns null. Which makes sense for a file that contains only a single line - which is consumed in line 15.
In other words, you're reading the file in line 15 but you're throwing away what you read.