Help coderanch get a
new server
by contributing to the fundraiser
  • 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
  • Ron McLeod
  • Paul Clapham
  • Devaka Cooray
  • Liutauras Vilda
Sheriffs:
  • Jeanne Boyarsky
  • paul wheaton
  • Henry Wong
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Tim Moores
  • Carey Brown
  • Mikalai Zaikin
Bartenders:
  • Lou Hamers
  • Piet Souris
  • Frits Walraven

Why am I getting a NullPointerException?

 
Ranch Hand
Posts: 41
Eclipse IDE Ubuntu Linux
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I want to save some preferences when the user closes the JFrame. I've implemented the WindowEvent to pick this up and set setDefaultCloseOperation(JFrame.DO_NOTHING). I'm calling the applications variable prefs.flush() which is giving the NullPointerException. I'm guessing that the nullpointerexception is thrown because I'm not actually handling the instance of jreport.prefs that I think I am. I would like some help finding out where I'm going wrong with handling the jreport.prefs instance. I declare JReport jreport in JReportFrame (which is instantiated by JReport). And I pass the object of JReport when calling JReportFrame:


and the JReportFrame constructor that receives this:


TIA
Adam
 
Bartender
Posts: 10780
71
Hibernate Eclipse IDE Ubuntu
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Adam Cripps wrote:I want to save some preferences when the user closes the JFrame. I've implemented the WindowEvent to pick this up and set setDefaultCloseOperation(JFrame.DO_NOTHING). I'm calling the applications variable prefs.flush() which is giving the NullPointerException. I'm guessing that the nullpointerexception is thrown because I'm not actually handling the instance of jreport.prefs that I think I am. I would like some help finding out where I'm going wrong with handling the jreport.prefs instance. I declare JReport jreport in JReportFrame (which is instantiated by JReport)...


The easiest thing to do is probably to add some debugging statements to print out the contents of the possible culprits, viz:it won't tell you why, but it may help you to narrow down the problem.

Winston
 
Adam Cripps
Ranch Hand
Posts: 41
Eclipse IDE Ubuntu Linux
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Thanks Winston. That gives as output when run - which supports my initial guess (I'm not handling the correct version of jreport). Am I correct in thinking that if I pass the jreport instance to the constructor and that with the declaration at the beginning of the class (JReport jreport;) that the whole class should be able to see jreport?
 
Rancher
Posts: 3742
16
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Adam Cripps wrote:Am I correct in thinking that if I pass the jreport instance to the constructor and that with the declaration at the beginning of the class (JReport jreport;) that the whole class should be able to see jreport?


No. You have to assign the jreport you pass to your constructor to the member variable. In your constructor you need the line
 
reply
    Bookmark Topic Watch Topic
  • New Topic