Java.awt.HeadlessException thrown from HeadlessGraphicsEnvironment.getDefaultScreenDevice

I need to do some image processing on a java server (Debian with Java version 1.6.0_12) and I get java.awt.HeadlessException from my code:

java.awt.HeadlessException
    at sun.java2d.HeadlessGraphicsEnvironment.getDefaultScreenDevice(HeadlessGraphicsEnvironment.java:64)
    at WaxOn.getDefaultConfiguration(WaxOn.java:341)

Even if java.awt.headless is set to true (as you can see from this code):

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?

+3
source share
2 answers

When without a headgear there is no screen device. The documentation is clear :

Throws: HeadlessException - if isHeadless () returns true

+4
source

, , . .

, ( ), .

+1

Source: https://habr.com/ru/post/1782182/


All Articles