java.awt.HeadlessException thrown from HeadlessGraphicsEnvironment.getDefaultScreenDevice
I need to do some image processing on a java server 开发者_如何学Python(Debian with java version "1.6.0_12"), and I am receiving java.awt.HeadlessException from my code:
java.awt.HeadlessException
at sun.java2d.HeadlessGraphicsEnvironment.getDefaultScreenDevice(HeadlessGraphicsEnvironment.java:64)
at WaxOn.getDefaultConfiguration(WaxOn.java:341)
Even when java.awt.headless is set to true (as evident by this code printing so):
if (!java.awt.GraphicsEnvironment.isHeadless())
{
logger.warn("Headless mode is not enabled");
}
else
{
logger.info("Headless mode");
}
This is the code that throws the exception:
public static GraphicsConfiguration getDefaultConfiguration()
{
GraphicsEnvironment ge = GraphicsEnvironment.getLocalGraphicsEnvironment();
GraphicsDevice gd = ge.getDefaultScreenDevice();
return gd.getDefaultConfiguration();
}
Any idea how to solve this?
When headless you don't have a screen device. The documentation is clear:
Throws: HeadlessException - if isHeadless() returns true
Your code appears to be getting the default graphics device configuration on a machine that doesn't have a usable graphic device. This doesn't make much sense, and is never going to work.
If you could explain why you are trying to do this (on a headless machine) we might be able to offer an alternative.
精彩评论