简体   繁体   中英

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);
  }
}

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

Multiple Linux distros have separate packages for the base of the JRE vs the JRE GUI.

On RHEL7/CentOS 7 for example, if you only have this package installed:

  • java-1.8.0-openjdk-headless

You also need to install this package:

  • java-1.8.0-openjdk

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.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM