aspose file tools*
The moose likes Java in General and the fly likes JOptionPane No X11 DISPLAY error Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Java in General
Bookmark "JOptionPane No X11 DISPLAY error" Watch "JOptionPane No X11 DISPLAY error" New topic
Author

JOptionPane No X11 DISPLAY error

Tarun Kumar Agrawal
Greenhorn

Joined: Jun 29, 2011
Posts: 17
I am trying to popup one message using JOptionPane. I am getting following error:



How can i fix this?
Rob Spoor
Sheriff

Joined: Oct 27, 2005
Posts: 19785
    
  20

By running the program from a windowed environment, like GNOME, KDE, Enlightenment, etc. Judging from that exception, you are running the program on a command line without any windowing system running, probably a server. So where are you going to display the JOptionPane?

If you get a HeadlessException you can sometimes prevent it by using the -Djava.awt.headless=true JVM property (which comes before the class name), but only if you don't really need the windowed environment. Which you do in this case.


SCJP 1.4 - SCJP 6 - SCWCD 5 - OCEEJBD 6
How To Ask Questions How To Answer Questions
Tarun Kumar Agrawal
Greenhorn

Joined: Jun 29, 2011
Posts: 17
I have deployed my code on one machine. I am running this from another machine using url: http://machine-ip:8080. Everything is displaying properly except that JOptionPane Message.
Rob Spoor
Sheriff

Joined: Oct 27, 2005
Posts: 19785
    
  20

Of course that won't work. The servlet / JSP code runs on the server, not on the client. That means that the JOptionPane dialog will be shown on the server, and there's no graphical environment there (or else you wouldn't get this exception). You'll have to use JavaScript to show messages to the user.
Tarun Kumar Agrawal
Greenhorn

Joined: Jun 29, 2011
Posts: 17
How can i call Javascript function from java servlet?
Jesper de Jong
Java Cowboy
Saloon Keeper

Joined: Aug 16, 2005
Posts: 14432
    
  23

You cannot. The servlet runs on the server, the JavaScript code in a HTML page runs on the client. The servlet sends back data (often in the form of a HTML page), which can also contain JavaScript. You could make the servlet return a page with some script in it that is run when the browser loads the page.

A web application does not work in exactly the same way as a desktop application, where you can display a message box at any time. You have to be aware of the HTTP request-response cycle, and what code runs where (server or client) and when.

Java Beginners FAQ - JavaRanch SCJP FAQ - The Java Tutorial - Java SE 8 API documentation
Rob Spoor
Sheriff

Joined: Oct 27, 2005
Posts: 19785
    
  20

One way to show a JavaScript dialog from a servlet is indeed by simply letting the generated HTML page contain code to show the dialog:
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: JOptionPane No X11 DISPLAY error