File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
The moose likes Beginning Java and the fly likes Why am I getting a NullPointerException? Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Murach's Java Servlets and JSP this week in the Servlets forum!
JavaRanch » Java Forums » Java » Beginning Java
Bookmark "Why am I getting a NullPointerException?" Watch "Why am I getting a NullPointerException?" New topic
Author

Why am I getting a NullPointerException?

Adam Cripps
Ranch Hand

Joined: Oct 01, 2011
Posts: 41

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
Winston Gutkowski
Bartender

Joined: Mar 17, 2011
Posts: 7526
    
  18

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


Isn't it funny how there's always time and money enough to do it WRONG?
Articles by Winston can be found here
Adam Cripps
Ranch Hand

Joined: Oct 01, 2011
Posts: 41

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?
Joanne Neal
Rancher

Joined: Aug 05, 2005
Posts: 3420
    
  12
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


Joanne
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Why am I getting a NullPointerException?
 
Similar Threads
Problem with Jakarta Commons Fileupload
Onchange JCombobox
problem reading output of a subprocess
Is this Dao?
Saving a filename in Preferences