我所有的 java 应用程序现在抛出 java.awt.headlessexception
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/21343529/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
All my java applications now throw a java.awt.headlessexception
提问by tbgeorge
So a couple days ago I had several working Javaapplications using the Swinglibrary, JFramein particular. They all worked perfectly fine and now they all throw this exception:
所以几天前,我有几个使用Swing库的Java应用程序,特别是JFrame。他们都工作得很好,现在他们都抛出了这个异常:
java.awt.headlessexception
I don't know what changed maybe my Javaversion got updated by accident.
我不知道发生了什么变化,也许我的Java版本被意外更新了。
Thanks for any help you can offer.
谢谢你的尽心帮助。
EDIT:
编辑:
Here's a small piece of code that gives me the exception.
这是一小段代码,给了我例外。
import javax.swing.JFrame;
public class test {
public static JFrame frame;
public static void main(String[] args) {
frame = new JFrame("test");
frame.setVisible(true);
frame.setLocationRelativeTo(null);
}
}
回答by MariuszS
HeadlessException
Thrown when code that is dependent on a keyboard, display, or mouse is called in an environment that does not support a keyboard, display, or mouse.
HeadlessException
在不支持键盘、显示器或鼠标的环境中调用依赖于键盘、显示器或鼠标的代码时抛出。
To set up headless mode use
设置无头模式使用
java -Djava.awt.headless=true
java -Djava.awt.headless=true
回答by mikedep333
Multiple Linux distros have separate packages for the base of the JRE vs the JRE GUI.
多个 Linux 发行版为 JRE 和 JRE GUI 的基础提供了单独的包。
On RHEL7/CentOS 7 for example, if you only have this package installed:
例如在 RHEL7/CentOS 7 上,如果你只安装了这个包:
- java-1.8.0-openjdk-headless
- java-1.8.0-openjdk-headless
You also need to install this package:
你还需要安装这个包:
- java-1.8.0-openjdk
- java-1.8.0-openjdk
回答by Alexander Ivanchenko
You can try to change a JRE you are currently using. Go to the "Run Configuration" of your project and change a JRE from your project's default to a Java Platform "standard" version.
您可以尝试更改当前使用的 JRE。转到项目的“运行配置”并将 JRE 从项目的默认版本更改为 Java 平台“标准”版本。