Encountered with "java.awt.HeadlessException: No X11 DISPLAY variable was set, but this program performed an operation which requires it."

huangapple go评论78阅读模式
英文:

Encountered with "java.awt.HeadlessException: No X11 DISPLAY variable was set, but this program performed an operation which requires it."

问题

以下是您要翻译的内容:

这个问题发生在我尝试运行一个非常简单的程序时。详细信息如下:

    引发的异常: java.awt.HeadlessException:
    未设置 X11 DISPLAY 变量
    但该程序执行了需要它的操作
            at java.desktop/java.awt.GraphicsEnvironment.checkHeadless(GraphicsEnvironment.java:165)
            at java.desktop/java.awt.Window.<init>(Window.java:540)
            at java.desktop/java.awt.Frame.<init>(Frame.java:423)
            at java.desktop/java.awt.Frame.<init>(Frame.java:388)
            at java.desktop/javax.swing.JFrame.<init>(JFrame.java:180)
            at StdDraw.init(StdDraw.java:669)
            at StdDraw.<clinit>(StdDraw.java:632)
            ... 1 more

我的 OpenJDK 版本是 "14.0.1" 2020-04-14

英文:

This problem occurred when I was trying to run a very simple program. The details are below:

    Caused by: java.awt.HeadlessException:
    No X11 DISPLAY variable was set,
    but this program performed an operation which requires it.
            at java.desktop/java.awt.GraphicsEnvironment.checkHeadless(GraphicsEnvironment.java:165)
            at java.desktop/java.awt.Window.&lt;init&gt;(Window.java:540)
            at java.desktop/java.awt.Frame.&lt;init&gt;(Frame.java:423)
            at java.desktop/java.awt.Frame.&lt;init&gt;(Frame.java:388)
            at java.desktop/javax.swing.JFrame.&lt;init&gt;(JFrame.java:180)
            at StdDraw.init(StdDraw.java:669)
            at StdDraw.&lt;clinit&gt;(StdDraw.java:632)
            ... 1 more

My OpenJDK version is "14.0.1" 2020-04-14

答案1

得分: 3

我假设你正在运行Linux,或者至少是某种形式的Unix。错误显示没有X11显示。系统要么是“无头”的,意味着没有图形界面,或者甚至没有监视器,要么你没有正确设置X11。

现在,如果你不打算在这个系统上使用图形界面,那么你的Java代码中肯定有某个地方在调用SWING组件。SWING是构建在较旧的AWT上的,这就是你在堆栈跟踪中看到两者的原因。

假设你有源代码,可以通过调试器逐步查找有问题的代码行并将其删除。或者,你需要在Linux系统上设置一个图形界面。

英文:

I'm presuming you are running Linux or at the very least some form of Unix. That error states there is no X11 display. Either the system is 'head-less' meaning no GUI or perhaps even monitor OR you don't have X11 setup properly.

Now if you don't mean to use a GUI on this system then something in your java code is making a call to a SWING component. SWING is built on the older AWT which is why you are seeing both in the stack trace above.

Presuming you have the source code, step through the debugger to find the offending line of code and remove it. OR you need to setup a GUI on your Linux system.

huangapple
  • 本文由 发表于 2020年10月23日 19:53:14
  • 转载请务必保留本文链接:https://go.coder-hub.com/64499484.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定