• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

NullPointerExcpetion Help

 
Greenhorn
Posts: 2
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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 ]
 
Ranch Hand
Posts: 1296
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
    Number of slices to send:
    Optional 'thank-you' note:
  • 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.
 
Marshal
Posts: 79178
377
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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.
 
reply
    Bookmark Topic Watch Topic
  • New Topic