createImage sometime returns null and sometime returns non-null.

V

vizlab

Hi:
I am debugging an Java standalone application and some servlets in
eclipse3.0.
I am using tomcat5.5 and jre1.5.0.
There is a file, called FlowChart.java, which will be used in the
Java standalone application and also used (called) by a servlet.


public class FlowChart extends JComponent implements
Serializable,MouseMotionListener,Printable {
...
Image backDrop=createImage(800,600);
...
}

When I debug the Java standalone application in eclipse, the
createImage() returns a non-null pointer. But when I debug the
servlets in eclipse, createImage() returns a null pointer.

Why???

One reason I guess is that eclipse uses its own libraries and
compiler to debug the standalone application, while the servlets are
debugged by using external jre1.5.0. There is some difference between
the jre1.5.0 and the eclipse's coming-with libraries. Is it true?

I have stucked on this problem for a long time.

Highly appreciate anyone giving me a way out!

Best
 
Joined
Sep 5, 2006
Messages
1
Reaction score
0
Components sometimes not displayable in constructor

Thanks to Andrew Thompson for references to updated documentation for JDK1.5...

A complicating factor is that components often don't appear to be displayable during
their constructor EVEN IF YOU HAVE FINISHED THE CONSTRUCTOR OF THE
UNDERLYING IMPLEMENTATION COMPONENT.

That is if you are using a class X which extends Frame in an application X.createImage
will return null during X's constructor even after the call of super(windowTitle).

So do the work which involves createImage in a separate initialisation step after the constructor - as far as I can see.
 
Joined
Oct 17, 2007
Messages
1
Reaction score
0
Possible Reasons

Hi Vizlab.
First of all, qouting from the Java API of Component.createImage():
The return value may be null if the component is not displayable. This will always happen if GraphicsEnvironment.isHeadless() returns true.

Your server is probably running headless - which is probably the default configuration (server guys usually snub swingers anyway ;-) ).
This can also happen on a swing application, if the component you're trying to use is not connected to a native screen resource (meanning - somewhere up in the containment hirarchy there is a heavyweight component).
You can call isDisplayable() prior to creating an image to test that.
See also here for and excellent java-on-server read: http://today.java.net/pub/a/today/2006/04/20/bringing-swing-to-the-web.html
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,769
Messages
2,569,582
Members
45,057
Latest member
KetoBeezACVGummies

Latest Threads

Top