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.
Joined: Dec 02, 2012
Thanks a lot!
I hadn't realized that checking if the line was null actually consumed that line, removing that statement and just checking if the line is null using ready() did that trick!
I'll change the name of my class too, hadn't thought it might already exist in java..
I’ve looked at a lot of different solutions, and in my humble opinion Aspose is the way to go. Here’s the link: http://aspose.com