Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
686 views
in Technique[技术] by (71.8m points)

swing - All my java applications now throw a java.awt.headlessexception

So a couple days ago I had several working Java applications using the Swing library, JFrame in particular. They all worked perfectly fine and now they all throw this exception:

java.awt.headlessexception

I don't know what changed maybe my Java version got updated by accident.

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);
  }
}
See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

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.

To set up headless mode use

java -Djava.awt.headless=true

Using Headless Mode in the Java SE Platform


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...