Win a copy of Kotlin in Action this week in the Kotlin forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic

Using a BufferedReader  RSS feed

 
Alex Richards
Greenhorn
Posts: 9
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I'm writing a program that uses a BufferedReader to read lines from a notepad file that I saved as altitude.txt.
Here is my code so far:



When I run this program so far, I get this error:

run:
Exception in thread "main" java.lang.NullPointerException
at rocketjava.Main.main(Main.java:19)
Java Result: 1
BUILD SUCCESSFUL (total time: 0 seconds)

Does anyone know what my problem appears to be?

On a side note, I realize that my while loop really doesn't do anything quite yet, but I'll get there after I get this error fixed first.
 
John Carr
Greenhorn
Posts: 17
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
It's because you didn't initialize the String array, you simply set it as null.

Change it to:


You'll most likely run into more errors, but I'll leave them for you to find.
 
Campbell Ritchie
Marshal
Posts: 55717
163
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
. . . and always close your Reader when you have finished with it.
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!