获得无头异常:未设置 X11 DISPLAY 变量

2022-09-01 14:38:40
Exception in thread "main" java.awt.HeadlessException:
    No X11 DISPLAY variable was set, but this program performed an operation which requires it.
        at java.awt.GraphicsEnvironment.checkHeadless(GraphicsEnvironment.java:159)
        at java.awt.Window.<init>(Window.java:432)
        at java.awt.Frame.<init>(Frame.java:403)
        at javax.swing.JFrame.<init>(JFrame.java:202)
        at DrawGUI.<init>(DrawGUI.java:15)
        at ShapeCreator.<init>(ShapeCreator.java:31)
        at ShapeCreator.main(ShapeCreator.java:138)

此错误消息是什么意思?我该如何解决它?


答案 1

我假设你正在尝试隧道进入一些unix盒子。

确保在 PuTTY 设置中启用了 X11 转发。

enter image description here


答案 2

这似乎是一个更普遍的SWING/AWT/JDK问题,只是JBOSS安装程序:

下面接受的答案为我解决了这个问题:

无法使用 ubuntu 运行 java gui 程序

(“sudo apt-get install openjdk-6-jdk”)


推荐