HeadlessException Error

V

vizlab

Dear all:
My servlets try to use some graphics. My JVM is 1.4.x.
At first, the servlet cannot show the graphics stuff. After I set
CATALINA_OPTS="-Djava.awt.headless=true", the servlets work "half
way". That's, they can show some graphics stuff, but not all. Some
graphics stuff, such as background, is missed. And I got the error
message below:

java.awt.HeadlessException
at java.awt.GraphicsEnvironment.checkHeadless(GraphicsEnvironment.java:121)
at java.awt.Window.<init>(Window.java:267)
at java.awt.Frame.<init>(Frame.java:398)
at java.awt.Frame.<init>(Frame.java:363)
at javax.swing.SwingUtilities$1.<init>(SwingUtilities.java:1623)
at javax.swing.SwingUtilities.getSharedOwnerFrame(SwingUtilities.java:1619)
at javax.swing.JOptionPane.getRootFrame(JOptionPane.java:1511)
at cobre.flowchart.FlowChart.loadBackdrop(FlowChart.java:1070)
at cobre.flowchart.FlowChart.load(FlowChart.java:1007)

I am surprised that the CATALINA_OPTS setting solves the graphics
problem only half way!

The problematic function is Toolkit.getGraphics().
I searched the related postings and found some possible
solutions:
(1) install xlib and set LD_LIBRARY_PATH to point to the lib. (I
have X11 installed, and tried to set LD_LIBRARY_PATH but got the same
error).
(2) set DISPLAY variable. (I set "export
DISPLAY=xxx.xxx.xxx.xxx:0.0" but no luck.).
(3) Use Xvfb to work around Headless. (I set "Xvfb :1 -screen 0
1600x1200x32", the system reported "Server is already active for
display 1...").

Did I do something wrong?
Or what else can I try?
Very grateful for your help.


Best Regards

Lian
 
G

Gerard Krupa

vizlab said:
Dear all:
My servlets try to use some graphics. My JVM is 1.4.x.
At first, the servlet cannot show the graphics stuff. After I set
CATALINA_OPTS="-Djava.awt.headless=true", the servlets work "half
way". That's, they can show some graphics stuff, but not all. Some
graphics stuff, such as background, is missed. And I got the error
message below:

java.awt.HeadlessException

I am surprised that the CATALINA_OPTS setting solves the graphics
problem only half way!

The problematic function is Toolkit.getGraphics().

For off-screen/headless images, you should be using
java.awt.image.BufferedImage.getGraphics() to get your graphics object
and then write it using an ImageWriter returned from
javax.imageio.ImageIO.getImageWritersByXXX().

HTH
Gerard
 

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,755
Messages
2,569,534
Members
45,007
Latest member
obedient dusk

Latest Threads

Top