我有以下用于创建光栅图像的代码。
BufferedImage img = new BufferedImage(width, height, BufferedImage.TYPE_3BYTE_BGR);
Graphics g = img.getGraphics();
g.setColor(backgroundColour);
g.fillRect(0, 0, width, height);
这在我的Windows机器和本地Ubuntu机器上运行,但是当转移到服务器时尝试调用X11服务器,显示堆栈跟踪。我该如何防止这种情况?
Exception in thread "main" java.lang.InternalError: Can't connect to X11
window server using 'localhost:10.0' as the value of the DISPLAY variable.
at sun.awt.X11GraphicsEnvironment.initDisplay(Native Method)
at
sun.awt.X11GraphicsEnvironment.access$200(X11GraphicsEnvironment.java:62)
at
sun.awt.X11GraphicsEnvironment$1.run(X11GraphicsEnvironment.java:178)
at java.security.AccessController.doPrivileged(Native Method)
at
sun.awt.X11GraphicsEnvironment.<clinit>(X11GraphicsEnvironment.java:142)
at java.lang.Class.forName0(Native Method)
at java.lang.Class.forName(Class.java:190)
at
java.awt.GraphicsEnvironment.getLocalGraphicsEnvironment(GraphicsEnvironment.java:82)
at
java.awt.image.BufferedImage.createGraphics(BufferedImage.java:1164)
at java.awt.image.BufferedImage.getGraphics(BufferedImage.java:1154)
at
org.xmlcml.cml.converters.molecule.fragments.Cml2PngTool.renderMolecule(Cml2PngTool.java:94)
at
org.xmlcml.cml.converters.molecule.fragments.Cml2PngTool.renderMolecule(Cml2PngTool.java:61)
at
org.xmlcml.cml.converters.molecule.fragments.FragmentGenerator.add2DCoordsAndRender(FragmentGenerator.java:180)
at
org.xmlcml.cml.converters.molecule.fragments.FragmentGenerator.write2dImage(FragmentGenerator.java:169)
at
org.xmlcml.cml.converters.molecule.fragments.FragmentGenerator.output2dImages(FragmentGenerator.java:486)
at
org.xmlcml.cml.converters.molecule.fragments.FragmentGenerator.generateMoieties(FragmentGenerator.java:443)
at
org.xmlcml.cml.converters.molecule.fragments.FragmentGenerator.createMoietiesAndFragments(FragmentGenerator.java:125)
at
org.xmlcml.cml.converters.molecule.fragments.CML2FragmentConverter.convert(CML2FragmentConverter.java:47)
at
org.xmlcml.cml.converters.AbstractConverter.process(AbstractConverter.java:1067)
at
org.xmlcml.cml.converters.AbstractConverter.processInputFile(AbstractConverter.java:1060)
at
org.xmlcml.cml.converters.AbstractConverter.runArgs(AbstractConverter.java:1016)
at
org.xmlcml.cml.converters.molecule.fragments.CML2FragmentConverter.main(CML2FragmentConverter.java:74)
答案 0 :(得分:7)
从命令行指定headless:
-Djava.awt.headless=true
或者来自代码:
System.setProperty("java.awt.headless", "true");
有关详细信息,请参阅http://www.oracle.com/technetwork/articles/javase/headless-136834.html。