Headless exception in java

2020-03-20 10:32发布

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?

3条回答
Root(大扎)
2楼-- · 2020-03-20 11:00

Class HeadlessException description

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

查看更多
一纸荒年 Trace。
3楼-- · 2020-03-20 11:01

My 2 cents.. you can also set java.awt.headless=true/false for example System.setProperty("java.awt.headless", "true"/"false");

查看更多
叛逆
4楼-- · 2020-03-20 11:11

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.

查看更多
登录 后发表回答