Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

Tags:

java

swing

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);
  }
}
like image 660
tbgeorge Avatar asked Jan 24 '14 22:01

tbgeorge


People also ask

What is Java AWT HeadlessException?

The java. awt. HeadlessException is a runtime exception in Java that occurs 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.

Is Java Swing still updated?

Swing and AWT will continue to be supported on Java SE 8 through at least March 2025, and on Java SE 11 (18.9 LTS) through at least September 2026.


1 Answers

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

like image 50
MariuszS Avatar answered Nov 16 '22 02:11

MariuszS