Win a copy of Re-engineering Legacy Software this week in the Refactoring forum
or Docker in Action in the Cloud/Virtualization forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

HeadlessException

 
Jon Camilleri
Ranch Hand
Posts: 664
Chrome Eclipse IDE
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Can you provide an example where a HeadlessException was thrown, and the environment and code involved?

 
Rob Spoor
Sheriff
Pie
Posts: 20497
54
Chrome Eclipse IDE Java Windows
  • Likes 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Suppose you have a UNIX / Linux server. This does not have any desktop environment like KDE or GNOME running; there's not even a so-called X server running for displaying anything graphically. In other words, you cannot display any frame, dialog, or other components on the screen. All that can be displayed is text through System.out and System.err.

Now suppose that on this system you want to display a frame. Without anything to display the frame on (remember, no desktop environment), how should the system display this frame? The answer: it simply can't, and throws an exception.

If you have such a system and you still need to use some of the classes in AWT / Swing (there's nothing wrong with using a Rectangle or Dimension, for instance), and the system is throwing HeadlessExceptions, you can pass the "-Djava.awt.headless=true" to the JVM to disable some of these exceptions. Still not all, because again, if there's nothing to display a frame on, the frame simply cannot be displayed.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic