Hi,
I am using the screenimage.java (available on source forge I believe) file to help me save some jfreecharts to disk but occasionally I get a null pointer problem when trying to do so.
I do not use the default jfreechart saving feature as I am saving multiple charts at once, all encapsulated in a jpanel.
The null pointer problem always occurs at the Paint() method of the graphics2d object in screenimage. I know that the object is not null, because I have them all become visible at the start of the run, but they may or may not be visible on screen when the call occurs.
Also once it has triggered a null pointer exception, the tab showing that panel also becomes blank. I have been trying for weeks to discover the source of the problem but I have yet to find it. It is especially frustrating as it only sometimes occurs.
Any assistance would be greatly appreciated!
Thanks!
Random null pointer problems when saving charts to disk
-
- JFreeChart Project Leader
- Posts: 11734
- Joined: Fri Mar 14, 2003 10:29 am
- antibot: No, of course not.
- Contact:
Re: Random null pointer problems when saving charts to disk
No-one can tell you the likely source of your NPE because you didn't post the stack trace and you didn't post the code that is generating the stack trace. I suggest that you step through the code with NetBeans or Eclipse (or whatever tool you like to use) and inspect the variables to determine what exactly is null.
David Gilbert
JFreeChart Project Leader
Read my blog
Support JFree via the Github sponsorship program
JFreeChart Project Leader
![Idea :idea:](./images/smilies/icon_idea.gif)
![Idea :idea:](./images/smilies/icon_idea.gif)
Re: Random null pointer problems when saving charts to disk
Hi David,
I know that there is too little information to determine the cause of the problem in my case, and to be frank my application is so large and so separate that trying to post the complete set of details I thought would be very confusing and obfuscate the problem at hand. I was wondering whether anyone else had any problems in saving a number of jfreechart objects contained in a JComponent to disk using the ScreenImage class or any other method, and how they managed to overcome the problem. Because the problem I have is that NONE of my objects are null, which makes me think it may be a more complicated issue (or bug in java) that comes from trying to paint a (possibly currently non-visible) object in swing.
But I will take your advice and debug my program some more, problem is that the error occurs somewhere inside the JComponent.paint(Graphics2D) method, which I cannot step through.
Thanks anyway!
I know that there is too little information to determine the cause of the problem in my case, and to be frank my application is so large and so separate that trying to post the complete set of details I thought would be very confusing and obfuscate the problem at hand. I was wondering whether anyone else had any problems in saving a number of jfreechart objects contained in a JComponent to disk using the ScreenImage class or any other method, and how they managed to overcome the problem. Because the problem I have is that NONE of my objects are null, which makes me think it may be a more complicated issue (or bug in java) that comes from trying to paint a (possibly currently non-visible) object in swing.
But I will take your advice and debug my program some more, problem is that the error occurs somewhere inside the JComponent.paint(Graphics2D) method, which I cannot step through.
Thanks anyway!
-
- Posts: 1
- Joined: Tue Jan 08, 2013 6:07 am
- antibot: No, of course not.
Re: Random null pointer problems when saving charts to disk
Infact what is happening is that even though the week ends are excluded from the chart, there is still vertical grid line displayed for Saturday. In addition, there is a vertical grid line for Monday as it should be. However, there is very small gap between these two vertical grin lines. When the dates are shown for these two grid lines, they are mixed. Unfortunately, I don't know how to submit an image here.