出现 HeadlessException:未设置 X11 DISPLAY 变量

发布于 2024-10-20 09:48:03 字数 620 浏览 4 评论 0原文

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)

这个错误信息是什么意思?我该如何解决它?

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)

What does this error message mean? And how can I solve it?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(6

也只是曾经 2024-10-27 09:48:03

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

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

在此处输入图像描述

I assume you're trying to tunnel into some unix box.

Make sure X11 forwarding is enabled in your PuTTY settings.

enter image description here

玩套路吗 2024-10-27 09:48:03

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

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

无法在 ubuntu 上运行 java gui 程序

("sudo apt-get install openjdk-6-jdk")

This appears to be a more general SWING/AWT/JDK problem that just the JBOSS installer:

The accepted answer below solved the issue for me :

Unable to run java gui programs with ubuntu

("sudo apt-get install openjdk-6-jdk")

暖风昔人 2024-10-27 09:48:03

您的系统没有 GUI 管理器。主要发生在 Solaris/Linux 机器中。如果您在其中使用 GUI,请确保安装了 GUI 管理器,并且您可能还想通过 DISPLAY 变量进行谷歌搜索。

Your system does not have a GUI manager. Happens mostly in Solaris/Linux boxes. If you are using GUI in them make sure that you have a GUI manager installed and you may also want to google through the DISPLAY variable.

柠北森屋 2024-10-27 09:48:03

我认为您正在尝试从具有 GUI 的 UNIX\LINUX 运行某些实用程序或 shell 脚本。无论如何

解决方案:伙计,你所需要的只是一个XServer和一个XServer。 X11 转发已启用。我使用XMing(XServer)。您已启用 X11 转发。只需安装它(XMing)并在使用 PuTTY 创建会话时保持其运行即可。

I think you are trying to run some utility or shell script from UNIX\LINUX which has some GUI. Anyways

SOLUTION: dude all you need is an XServer & X11 forwarding enabled. I use XMing (XServer). You are already enabling X11 forwarding. Just Install it(XMing) and keep it running when you create the session with PuTTY.

风渺 2024-10-27 09:48:03

就我而言,这不是我的 Arch Linux 上的显示服务器或窗口管理器的问题。其他 GUI 应用程序可以从终端顺利启动。经过一番挖掘后,我决定打印出所有系统属性 (System.getProperties()),并意识到我使用的 JVM(java 可执行文件)不是来自JDK是从Oracle网站下载的,但是是从我系统的包管理器提供的。

显然,我的系统安装了无头版本的 openjdk。此 openjdk 包提供的 JVM 不支持显示和外围设备,因此是无头的。这就是我收到 HeadlessException 的原因。

有些人建议安装常规版本的 openjdk,其中 JVM 以非无头模式运行,除非另有指示。其他解决方案是始终使用从 Oracle 下载的 JDK 中的 JVM。我选择了后者。

我在 bash 中设置了 java 关键字的别名。

alias java="/path/to/downloaded/jdk/bin/java "

然后,我使用以下代码测试了两个 JVM 的图形功能:

import java.awt.GraphicsEnvironment;

// Inside main method:
System.out.println(GraphicsEnvironment.isHeadless());

上面的代码在使用系统 JVM 执行时打印 true,而在使用下载的 JVM 执行时打印 false。我使用 Swing 的实际代码也运行得很好。

In my case it was not a problem with the display server or a window manager on my Arch Linux. Other GUI apps launched without a hitch from terminal. After a little digging I decided to print out all the system properties (System.getProperties()) and realized that the JVM (java executable) I was using was not from the JDK downloaded from Oracle's website but from the one supplied by my system's package manager.

Apparently, my system had headless version of openjdk installed. The JVM supplied by this openjdk package had no support for display and peripheral devices, hence headless. That's why I was getting the HeadlessException.

Some folks suggest to install the regular version of openjdk where JVM runs in non-headless mode unless instructed to do otherwise. Other solution is to always use JVM from the JDK you downloaded from Oracle. I chose the latter.

I setup an alias in my bash to java keyword.

alias java="/path/to/downloaded/jdk/bin/java "

I then tested the graphics capabilities of both JVMs with this code:

import java.awt.GraphicsEnvironment;

// Inside main method:
System.out.println(GraphicsEnvironment.isHeadless());

The above code printed true when executed with system's JVM and printed false when executed with downloaded JVM. My actual code using Swing ran fine too.

只涨不跌 2024-10-27 09:48:03

问题陈述 – 尝试从应用程序初始化 java.awt.Component 时出现 java.awt.HeadlessException,因为 tomcat 环境没有任何 head(终端)。

问题 – Linux 虚拟环境的设置没有虚拟显示终端。尝试安装虚拟显示-Xvfb,但Xvfb已被redhat社区下架。

解决方案 – 使用 yum install xorg-x11-drv-vmware.x86_64 安装“xorg-x11-drv-vmware.x86_64”并执行 startx。最后使用export DISPLAY=:0.0将显示设置为:0.0,然后执行xhost +

Problem statement – Getting java.awt.HeadlessException while trying to initialize java.awt.Component from the application as the tomcat environment does not have any head(terminal).

Issue – The linux virtual environment was setup without a virtual display terminal. Tried to install virtual display – Xvfb, but Xvfb has been taken off by the redhat community.

Solution – Installed ‘xorg-x11-drv-vmware.x86_64’ using yum install xorg-x11-drv-vmware.x86_64 and executed startx. Finally set the display to :0.0 using export DISPLAY=:0.0 and then executed xhost +

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文