java.awt.HeadlessException
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/15658493/
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
java.awt.HeadlessException
提问by shiva tatikonda
JFileChooser chooser = new JFileChooser();
JDialog dialog=new JDialog();
dialog.setAlwaysOnTop(true);
/*System.out.println("is always on top?"+dialog.isAlwaysOnTop());*/
chooser.setFileSelectionMode(JFileChooser.DIRECTORIES_ONLY);
int returnVal = chooser.showOpenDialog(dialog);
String path = null;
if(returnVal == JFileChooser.APPROVE_OPTION) {
path=chooser.getSelectedFile().getAbsolutePath();
}
I have written this code in Servlet's doGet
method.when i deployed in linux server getting following exception:
我已经在 Servlet 的doGet
方法中编写了这段代码。当我部署在 linux 服务器中时出现以下异常:
java.awt.HeadlessException
at java.awt.GraphicsEnvironment.checkHeadless(GraphicsEnvironment.java:159)
Does anyone know how to over come this?
有谁知道如何克服这个?
回答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.
无头异常
在不支持键盘、显示器或鼠标的环境中调用依赖于键盘、显示器或鼠标的代码时抛出。
回答by mthmulders
Your HTML form should have something like this:
你的 HTML 表单应该是这样的:
<form action="upload" method="post" enctype="multipart/form-data">
<input type="file" name="file" />
<input type="submit" />
</form>
Then, using Apache Commons FileUpload, you can process the uploaded file in your Servlet. See their User Guideand FAQfor more information.
然后,使用Apache Commons FileUpload,您可以在 Servlet 中处理上传的文件。有关更多信息,请参阅他们的用户指南和常见问题解答。
回答by shazin
Web Applications usually run on Back End servers which are headless. Better to avoid any GUI except the ones that run within an Applet.
Web 应用程序通常运行在无头的后端服务器上。除了在 Applet 中运行的 GUI 之外,最好避免使用任何 GUI。
回答by Ray Foss
In Fedora and some other linux distros, only headless java runtime is installed by default. You may need to install the full java runtime:
在 Fedora 和其他一些 linux 发行版中,默认情况下只安装无头 java 运行时。您可能需要安装完整的 java 运行时:
sudo yum install java-1.8.0-openjdk
sudo yum install java-1.8.0-openjdk
Source: https://github.com/chatty/chatty/issues/261#issuecomment-392228006
来源:https: //github.com/chatty/chatty/issues/261#issuecomment-392228006
回答by MarioG
If you run this under Linux with low Permission you get this:
如果你在 Linux 下以低权限运行它,你会得到:
java.lang.RuntimeException: Failed to create component for 'frame' reason: java.awt.HeadlessException
at Pp$_run_closure1.doCall(Pp2.groovy:17)
at Pp.run(Pp2.groovy:15)
at Pp$run.call(Unknown Source)
at Pp.main(Pp2.groovy:12)
Caused by: java.awt.HeadlessException
you have to run it with the right permissions.
您必须以正确的权限运行它。
First try this with maximum Permissions:
首先尝试使用最大权限:
sudo groovy MyClass.groovy
This should solve your Problem.
这应该可以解决您的问题。