| Author |
NullPointerExcpetion Help
|
Jack O'Herrer
Greenhorn
Joined: Feb 21, 2008
Posts: 2
|
|
Hey Everyone, I'm hoping that one of you can help me with a problem I'm having. The code I'm trying to run is compiling fine, but I'm getting a NullPointerException error when I'm actually trying to run it. What I think is happening is the stack is for some reason being initialized with a null value at the beginning. Any help would be greatly appreciated. Heres the code [ February 21, 2008: Message edited by: Jack O'Herrer ] [ February 21, 2008: Message edited by: Jack O'Herrer ]
|
 |
Garrett Rowe
Ranch Hand
Joined: Jan 17, 2006
Posts: 1295
|
|
I haven't read through all your code, but you do have a problem here. The String you are assigning in your constructor isn't the same as the String you declare as an instance variable. Can you figure out why?
|
Some problems are so complex that you have to be highly intelligent and well informed just to be undecided about them. - Laurence J. Peter
|
 |
Jack O'Herrer
Greenhorn
Joined: Feb 21, 2008
Posts: 2
|
|
Aha! Thanks, I didn't realize that I reinitialized the string variable. Now that thats fixed, I'm having problems with writing to the output file. Even when I try to hardcode the line outFile.println("This is a test"); I'm getting nothing in the file P5.txt Thanks again for the help
|
 |
Garrett Rowe
Ranch Hand
Joined: Jan 17, 2006
Posts: 1295
|
|
|
Try closing your PrintWriter when you are done writing, aside from that just being a good habit to get into, it also automatically calls the flush() method to ensure all the data in the buffer gets written to the output file.
|
 |
Campbell Ritchie
Sheriff
Joined: Oct 13, 2005
Posts: 32675
|
|
Another suggestion: you are not implementing the equals() method correctly; it ought to take Object as a parameter type. Please do a search for equals(); it is discussed frequently on these boards.
|
 |
 |
|
|
subject: NullPointerExcpetion Help
|
|
|