Home pageFind It!Contact PJAPJA documentation

PJA

 PJA Toolkit forum

This forum is dedicated to PJA Toolkit.
You may read freely the messages it contents. If you want to write a message or answer to a subject, subscribe to it first.

Subjects Recent messages Login Subscribe

Messages of subject HeadlessException with Java 1.5, without PJA

JoeH

Member since : Jan 26, 2006
Messages : 1
 Jan 26, 2006 at 3:22 PM
Hi,

We've been using PJA for some years now on a project, running on Java 1.4. We recently moved up to Java 1.5, and encountered the java.lang.AbstractMethodError described in:
http://www.eteks.com/pja/en/forum/viewSubject.jsp?subjectId=518

I read with interest in this thread that PJA is no longer required when using Java 1.5. If we remove PJA from Tomcat's JAVA_OPTS, and take out the System property settings, we get the following exception:

java.awt.HeadlessException: No X11 DISPLAY variable was set, but this program performed an operation which requires it.
at java.awt.GraphicsEnvironment.checkHeadless(GraphicsEnvironment.java:159)
at java.awt.Window.<init>(Window.java:317)
at java.awt.Frame.<init>(Frame.java:419)
at java.awt.Frame.<init>(Frame.java:384)

with "headless=false".

If we set "headless=true", we get:

java.awt.HeadlessException
at java.awt.GraphicsEnvironment.checkHeadless(GraphicsEnvironment.java:159)
at java.awt.Window.<init>(Window.java:317)
at java.awt.Frame.<init>(Frame.java:419)
at java.awt.Frame.<init>(Frame.java:384)


The code that's throwing these exceptions is:

Image image = Toolkit.getDefaultToolkit().getImage(theFile.getCanonicalPath());
MediaTracker mediaTracker = new MediaTracker(new Frame());

This is on a RedHat Enterprise Linux ES release 3, that isn't set up to be graphical - it does have the XFree86 libs on, though.

Has anyone else had this kind of problem after upgrading to Java 1.5?

Cheers,

-Joe

Manu

Location : Paris / France
Member since : Apr 29, 2003
Messages : 394
 Jan 29, 2006 at 1:01 PM
> Has anyone else had this kind of problem after upgrading to Java 1.5?

If you can change your program, you should remove any reference to java.awt.Frame classes :
- Create blank images using java.awt.image.BufferedImage class
- Load images using the static method read in javax.imageio.ImageIO class : http://java.sun.com/j2se/1.5.0/docs/api/javax/imageio/ImageIO.html . By the way, note that this class has some methods that are very easy to use when writing an image on an output stream.

I tried these changes on PJA ToolkitDemo.java file (supplied in src directory of PJA Toolkit download), and the program worked correctly with J2SE 5.0 on a Debian Linux system with no X11 libs installed.
I replaced the creation of an image :
  java.awt.Frame frame = new java.awt.Frame ();
  frame.addNotify ();
  java.awt.Image image = frame.createImage (width, height);

by :
  java.awt.Image image = new java.awt.image.BufferedImage (width, height,
      java.awt.image.BufferedImage.TYPE_INT_RGB);


and I replaced the load of a image :
  java.awt.Image image = java.awt.Toolkit.getDefaultToolkit ().getImage ("photo.jpg");
  java.awt.MediaTracker imageTracker = new java.awt.MediaTracker (new java.awt.Frame ());
  imageTracker.addImage (image, 0);
  imageTracker.waitForID (0);

by :
  java.awt.Image image = javax.imageio.ImageIO.read(new java.io.File("photo.jpg"));

I hope this will help you.
I know this isn't the best solution for people upgrading to J2SE 5.0 who are unable to change their program, but java.awt.image.BufferedImage and javax.imageio.ImageIO have been around for a while now, and graphic libraries should at least have been updated now.

As the developer of PJA Toolkit, I'm really happy that this library helped so much people around the world, but this library can be seen mainly as a Java patch for UNIX users with various X11 configurations, and as such, I'm glad also that people can avoid this patch now with J2SE 5.0. :-)
---
Manu (moderator/modérateur)

mianor

Location : Montreal / Canada
Member since : Jul 18, 2006
Messages : 1
 Jul 18, 2006 at 11:18 PM
Hi,

I have an issue using PJA Toolkit on a headless Solaris 10 system with Sun Server and Java 1.5 (was working great on previous server version with 1.4 :-))

I replaced the code as you suggested to do, and recompile the source code for Java 1.5 and recreated the jar file.

Now when I get the Graphics from an image previously instantiated :

Image img = new BufferedImage (jsm.getWidth(), jsm.getHeight(), java.awt.image.BufferedImage.TYPE_INT_RGB);
Graphics g = img.getGraphics();
g.setColor(Color.white);
g.fillRect(0, 0, jsm.getWidth(), jsm.getHeight());
jsm.paint(g);
sendGIFImage(img, res);

A NullPointerException occurs without more explanations :

java.lang.NullPointerException
at sun.java2d.SunGraphicsEnvironment$1.run(SunGraphicsEnvironment.java:189)
at java.security.AccessController.doPrivileged(Native Method)
at sun.java2d.SunGraphicsEnvironment.<init>(SunGraphicsEnvironment.java:94)
at com.eteks.java2d.PJAGraphicsEnvironment.<init>(PJAGraphicsEnvironment.java:67)
at sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method)
at sun.reflect.NativeConstructorAccessorImpl.newInstance(NativeConstructorAccessorImpl.java:39)
at sun.reflect.DelegatingConstructorAccessorImpl.newInstance(DelegatingConstructorAccessorImpl.java:27)
at java.lang.reflect.Constructor.newInstance(Constructor.java:494)
at java.lang.Class.newInstance0(Class.java:350)
at java.lang.Class.newInstance(Class.java:303)
at java.awt.GraphicsEnvironment.getLocalGraphicsEnvironment(GraphicsEnvironment.java:68)
at java.awt.image.BufferedImage.createGraphics(BufferedImage.java:1141)
at java.awt.image.BufferedImage.getGraphics(BufferedImage.java:1131)
at com.cmtek.mobile.servlet.SeatMapImageServlet.displaySMapImage(SeatMapImageServlet.java:123)
at com.cmtek.mobile.servlet.SeatMapImageServlet.doGetPJA(SeatMapImageServlet.java:72)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
at java.lang.reflect.Method.invoke(Method.java:585)
at com.eteks.awt.servlet.PJAServlet.HttpMethodInvoke(PJAServlet.java:795)
at com.eteks.awt.servlet.PJAServlet.doGet(PJAServlet.java:651)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:747)
at com.eteks.awt.servlet.PJAServlet.servicePJA(PJAServlet.java:787)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
at java.lang.reflect.Method.invoke(Method.java:585)
at com.eteks.awt.servlet.PJAServlet.HttpMethodInvoke(PJAServlet.java:795)
at com.eteks.awt.servlet.PJAServlet.service(PJAServlet.java:777)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:860)
at com.eteks.awt.servlet.PJAServlet.servicePJA(PJAServlet.java:639)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
at java.lang.reflect.Method.invoke(Method.java:585)
at com.eteks.awt.servlet.PJAServlet.service(PJAServlet.java:608)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
at java.lang.reflect.Method.invoke(Method.java:585)
at org.apache.catalina.security.SecurityUtil$1.run(SecurityUtil.java:249)
at java.security.AccessController.doPrivileged(Native Method)
at javax.security.auth.Subject.doAsPrivileged(Subject.java:517)
at org.apache.catalina.security.SecurityUtil.execute(SecurityUtil.java:282)
at org.apache.catalina.security.SecurityUtil.doAsPrivilege(SecurityUtil.java:165)
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:257)
at org.apache.catalina.core.ApplicationFilterChain.access$000(ApplicationFilterChain.java:55)
at org.apache.catalina.core.ApplicationFilterChain$1.run(ApplicationFilterChain.java:161)
at java.security.AccessController.doPrivileged(Native Method)
at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:157)
at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:263)
at org.apache.catalina.core.StandardPipeline.invoke(StandardPipeline.java:551)
at org.apache.catalina.core.StandardContextValve.invokeInternal(StandardContextValve.java:225)
at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:173)
at org.apache.catalina.core.StandardPipeline.invoke(StandardPipeline.java:551)
at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:161)
at org.apache.catalina.core.StandardPipeline.invoke(StandardPipeline.java:551)
at org.apache.catalina.core.ContainerBase.invoke(ContainerBase.java:933)
at com.sun.enterprise.web.connector.httpservice.HttpServiceProcessor.process(HttpServiceProcessor.java:226)
at com.sun.enterprise.web.HttpServiceWebContainer.service(HttpServiceWebContainer.java:2071)


Any ideas? Thanks!!


Home pageFind It!ContactTop

© Copyrights 1997-2023 eTeks - All rights reserved

PJAPJA documentation