Welcome to the Java Programming Forums


The professional, friendly Java community. 21,500 members and growing!


The Java Programming Forums are a community of Java programmers from all around the World. Our members have a wide range of skills and they all have one thing in common: A passion to learn and code Java. We invite beginner Java programmers right through to Java professionals to post here and share your knowledge. Become a part of the community, help others, expand your knowledge of Java and enjoy talking with like minded people. Registration is quick and best of all free. We look forward to meeting you.


>> REGISTER NOW TO START POSTING


Members have full access to the forums. Advertisements are removed for registered users.

Results 1 to 8 of 8

Thread: JOptionPane not working?

  1. #1
    Junior Member
    Join Date
    Feb 2013
    Posts
    11
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default JOptionPane not working?

    Hey guys,

    I wrote a program that required the use of JOptionPane. The program compiled without an issue. However, when I try to run it, I get these error messages:

    Exception in thread "main" java.awt.HeadlessException:
    No X11 DISPLAY variable was set, but this program performed an operation which requires it.
    at java.awt.GraphicsEnvironment.checkHeadless(Graphic sEnvironment.java:207)
    at java.awt.Window.<init>(Window.java:535)
    at java.awt.Frame.<init>(Frame.java:420)
    at java.awt.Frame.<init>(Frame.java:385)
    at javax.swing.SwingUtilities$SharedOwnerFrame.<init> (SwingUtilities.java:1759)
    at javax.swing.SwingUtilities.getSharedOwnerFrame(Swi ngUtilities.java:1834)
    at javax.swing.JOptionPane.getRootFrame(JOptionPane.j ava:1697)
    at javax.swing.JOptionPane.showInputDialog(JOptionPan e.java:576)
    at javax.swing.JOptionPane.showInputDialog(JOptionPan e.java:525)
    at javax.swing.JOptionPane.showInputDialog(JOptionPan e.java:475)
    at Project0.main(Project0.java:8)


    I worked on a Macintosh using terminal. Is there something that I need to download in order to make them work?


  2. #2
    Super Moderator Norm's Avatar
    Join Date
    May 2010
    Location
    Eastern Florida
    Posts
    25,140
    Thanks
    65
    Thanked 2,720 Times in 2,670 Posts

    Default Re: JOptionPane not working?

    Can you make a small, complete program that compiles, executes and show the problem?

    Did you read the API doc for that exception?
    If you don't understand my answer, don't ignore it, ask a question.

  3. #3
    Junior Member
    Join Date
    Feb 2013
    Posts
    11
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default Re: JOptionPane not working?

    Edit: API doc?

    It is a small program that I just used just to see if the JOptionPane would work. It compiles. When I run it, it displays what I quoted in my original post

    import javax.swing.JOptionPane;
    public class Project0
    {
        public static void main(String [] args){
            String name="";
            int age=0;
     
            name=JOptionPane.showInputDialog(null, "Please enter your name: ");
            age=Integer.parseInt(JOptionPane.showInputDialog(null, "Please enter your age: "));
     
            JOptionPane.showMessageDialog(null, "Hello" + name + ". You are " + age + "years old!");
        }
    }

  4. #4
    Super Moderator Norm's Avatar
    Join Date
    May 2010
    Location
    Eastern Florida
    Posts
    25,140
    Thanks
    65
    Thanked 2,720 Times in 2,670 Posts

    Default Re: JOptionPane not working?

    java.awt.HeadlessException
    That's a class. It is documented in the Java API doc: Java Platform SE 7

    It works on my Windows7 system.
    If you don't understand my answer, don't ignore it, ask a question.

  5. #5
    Junior Member
    Join Date
    Feb 2013
    Posts
    11
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default Re: JOptionPane not working?

    Thanks for the link.

    So I have to have this Java Platform on my computer in order for the JOptionPane to work?

  6. #6
    Super Moderator Norm's Avatar
    Join Date
    May 2010
    Location
    Eastern Florida
    Posts
    25,140
    Thanks
    65
    Thanked 2,720 Times in 2,670 Posts

    Default Re: JOptionPane not working?

    You must have a java program to have gotten the error message.

    Does this mean anything: No X11 DISPLAY variable was set,
    If you don't understand my answer, don't ignore it, ask a question.

  7. #7
    Junior Member
    Join Date
    Feb 2013
    Posts
    11
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default Re: JOptionPane not working?

    ^I have no idea what the message means.

    Huh... looking at my applications, it seems that Java VisualM came with the Macintosh. Does that mean anything?

  8. #8
    Junior Member
    Join Date
    Feb 2013
    Posts
    11
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default Re: JOptionPane not working?

    I ran it on Eclipse and it worked fine. I guess Terminal doesn't do GUIs?

Similar Threads

  1. Display in JOptionPane
    By t-rank in forum What's Wrong With My Code?
    Replies: 4
    Last Post: October 19th, 2010, 12:09 AM
  2. Change to JOptionPane
    By Liuric in forum What's Wrong With My Code?
    Replies: 2
    Last Post: October 1st, 2010, 12:07 AM
  3. JOptionPane using If and Else
    By Liuric in forum Member Introductions
    Replies: 7
    Last Post: October 1st, 2010, 12:05 AM
  4. Replies: 4
    Last Post: January 27th, 2009, 12:03 AM