java.awt.HeadlessException thrown from HeadlessGraphicsEnvironment.getDefaultScreenDevice

牧云@^-^@ 提交于 2019-12-04 04:05:55

问题


I need to do some image processing on a java server (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?


回答1:


When headless you don't have a screen device. The documentation is clear:

Throws: HeadlessException - if isHeadless() returns true




回答2:


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.



来源:https://stackoverflow.com/questions/4534400/java-awt-headlessexception-thrown-from-headlessgraphicsenvironment-getdefaultscr

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!