7

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?

nsthethunderbolt
  • 2,059
  • 1
  • 17
  • 24
  • 6
    It is typically thrown in a JVM that is running in a machine with no visual output (no screen) - an [headless environment](http://stackoverflow.com/questions/4647719/what-does-headless-mean). – Andrew Thompson Dec 26 '12 at 09:53

4 Answers4

7

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

7

My 2 cents. You can also set -Djava.awt.headless=true/false (command line), or for example System.setProperty("java.awt.headless", "true"/"false");

Matthieu
  • 2,736
  • 4
  • 57
  • 87
Vinayak Pahalwan
  • 2,915
  • 4
  • 26
  • 34
0

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.

Utpal
  • 9
  • 1
0

Exception in JDBC Connection for an AS400 System

If you are using a JDBC Connection for an AS400 System then this indicates that the driver is asking to enter the credentials in the prompt but it fails because it's not an interactive session. The credentials provided for that connection are invalid and the default option is to ask them by the prompt.

If you try multiple times with the same wrong credentials, then the AS400 system is able to block you. Then you need to unblock your userId to establish the connection.

Sivaram Rasathurai
  • 5,533
  • 3
  • 22
  • 45
  • The question is about headless systems; not AS400 JDBC – Matthieu Mar 27 '22 at 22:53
  • @Maththieu, This Q wasn't related to AS400 System. but if you use AS400 system and get a Headless exception, this may help you. Additionally, when I googled the exception, I landed on this page, that's why I added this answer here. Thanks for understanding – Sivaram Rasathurai Jun 04 '22 at 04:49