Skip to Main Content

Java SE (Java Platform, Standard Edition)

Announcement

For appeals, questions and feedback about Oracle Forums, please email oracle-forums-moderators_us@oracle.com. Technical questions should be asked in the appropriate category. Thank you!

headless mode and java.awt.GraphicsEnvironment

843807Apr 2 2004 — edited Apr 7 2004
Ive been trying to make a simple servlet work that generates an image on the fly using BufferedImage. Like a number of posts on this forum, Im having difficulty, always running into a NoClassDefFoundError: sun/awt/X11GraphicsEnvironment error on my headless server, running JDK1.4.2, despite java.awt.headless being set to true.

Looking thorugh the source code in src.zip on my jdk, I came across this in java.awt.GraphicsEnvironment and wonder if anybody else agrees.
try {    
  localEnv = (GraphicsEnvironment) Class.forName(nm).newInstance();    
  if (isHeadless()) {       
    localEnv = new HeadlessGraphicsEnvironment(localEnv);    
  }
} catch (ClassNotFoundException e) {    
  throw new Error("Could not find class: "+nm); 
} catch (InstantiationException e) {    
 throw new Error("Could not instantiate Graphics Environment: " + nm);
} catch (IllegalAccessException e) {   
 throw new Error ("Could not access Graphics Environment: " + nm);
}
Surely, it would be better to check for headless first, and if not, then get the non-headless class? Especialy since this is where it falls over in most peoples code.
Comments
Locked Post
New comments cannot be posted to this locked post.
Post Details
Locked on May 5 2004
Added on Apr 2 2004
3 comments
1,305 views