Win a copy of Re-engineering Legacy Software this week in the Refactoring forum
or Docker in Action in the Agile forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

NullPointerExcpetion Help

 
Jack O'Herrer
Greenhorn
Posts: 2
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 1296
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator


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?
 
Jack O'Herrer
Greenhorn
Posts: 2
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 1296
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 48386
56
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
 
Don't get me started about those stupid light bulbs.
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic