java java中的无头异常
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/14038793/
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
Headless exception in java
提问by nsthethunderbolt
I heard that when we use awt or swing, while creating a FRAME, an unchecked exception may be thrown which is "Headless exception". I never got this exception. Can anyone tell when this exception is thrown?
听说我们在使用awt或者swing的时候,在创建FRAME的时候,可能会抛出一个unchecked exception,就是“Headless exception”。我从来没有得到这个例外。谁能告诉什么时候抛出这个异常?
采纳答案by nsthethunderbolt
Class HeadlessException
description
班级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.
在不支持键盘、显示器或鼠标的环境中调用依赖于键盘、显示器或鼠标的代码时抛出。
For more details http://docs.oracle.com/javase/7/docs/api/java/awt/HeadlessException.html
有关更多详细信息,请访问http://docs.oracle.com/javase/7/docs/api/java/awt/HeadlessException.html
回答by Vinayak Pahalwan
My 2 cents.. you can also set java.awt.headless=true/false for example System.setProperty("java.awt.headless", "true"/"false");
我的 2 美分.. 你也可以设置 java.awt.headless=true/false 例如 System.setProperty("java.awt.headless", "true"/"false");
回答by Utpal
This exception is thrown when we try to instantiate an awt or a swing component from a system that doesn't has a terminal (head). Usually this happens on a virtual box unix system. Need to install the xbfb component and set the DISPLAY parameter before executing the program.
当我们尝试从没有终端(头)的系统中实例化 awt 或摆动组件时,会抛出此异常。通常这发生在虚拟机 unix 系统上。执行程序前需要安装xbfb组件并设置DISPLAY参数。