This week's book giveaway is in the OCAJP 8 forum. We're giving away four copies of OCA Java SE 8 Programmer I Study Guide and have Edward Finegan & Robert Liguori on-line! See this thread for details.
Welcome to JavaRanch. Please UseCodeTags when you post source code.
About the NullPointerException: Carefully look at the error message, especially the stack trace. It should tell you exactly in which line of the source code the exception happens. Look at that line in your source code and think of what is null there that isn't supposed to be null. You usually get a NullPointerException when you try to call a method on a variable that is null.
Welcome to the Ranch I have added code tags because you are new (as Jesper mentioned), and you can see how much better the post looks.
Beware of having Readers as fields of the class; they are often better declared as local variables. You are failing to close the Reader; this can potentially lead to resource leaks. You ought to close the Reader in a "finally" block; example here.
Don't use system.out in a catch; use System.err. Your error message is a little too basic; you might do better with e.printStackTrace(), which gives you more details. Beware of the read() method, which only reads one character at a time, and often doesn't provide what you need. If you need lots of characters, you might do well to put your reading into a loop.
Joined: May 06, 2010
Ahhh...Thank you. I'll be sure to add CodeTags in the future.
I found my problem. I had declared my BufferedReader outside of my constructor. Then of course when I declared it again within the constructor, it wiped the original.
Easy fix was to just delete the BufferedReader before readIt within my constructor.
Sooner or later I'm going to stop doing that.
Joined: Oct 13, 2005
Alan Branch wrote: . . . Then of course when I declared it again within the constructor, it wiped the original. . . . .
No, it didn't wipe the original. It created two separate references and ignored the original. This is called shadowing.
Joined: May 06, 2010
Ahhh... Thank you. It's important to know the right nomenclature and what exactly is going on.