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 4 of 4

Thread: JOPtionPane error

  1. #1
    Junior Member
    Join Date
    May 2018
    Posts
    8
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default JOPtionPane error

    Hi guys im trying to make a JOption box that asks a user to input his/her name and display it back to them but keeping getting the following compile error: Cannot find symbol JOptionPane.showMessageDialog the code looks as follows, any input will be appreciated.

    import javax.swing.JOptionPane;

    public class Wack
    {
    public static void main(String args[])
    {
    String userInput = "";


    userInput = JOptionPane.showInputDialog("Please enter your name");


    userInput = "your name is " + userInput;

    JOptionPane.showMesssageDialog(null, userInput);

    }
    }

  2. #2

    Default Re: JOPtionPane error

    you can pass any JComponent as Object in the conctructor for JOptionPane,

    in your case is there null value - JOptionPane.showMessageDialog(null, "ErrorMsg", for example

    JOptionPane.showMessageDialog(myFrame,
    "ErrorMsg", "Failure", JOptionPane.ERROR_MESSAGE);

  3. #3
    Member
    Join Date
    Dec 2013
    Location
    Honolulu
    Posts
    74
    Thanks
    1
    Thanked 0 Times in 0 Posts

    Default Re: JOPtionPane error

    System.in.println( " " ) method is used to ask for a user input.

    String [variable name] = " "; will do the trick. It will require an input from the user.

  4. #4
    Junior Member
    Join Date
    Sep 2017
    Location
    South Africa
    Posts
    12
    Thanks
    2
    Thanked 1 Time in 1 Post

    Default Re: JOPtionPane error

    Quote Originally Posted by priya456 View Post
    you can pass any JComponent as Object in the conctructor for JOptionPane,

    in your case is there null value - JOptionPane.showMessageDialog(null, "ErrorMsg", for example

    JOptionPane.showMessageDialog(myFrame,
    "ErrorMsg", "Failure", JOptionPane.ERROR_MESSAGE);
    This message is a straight copy from a stack overflow website here \\https://stackoverflow.com/questions/...-in-a-jframe\\ , it doesnt even answer ops question properly. ( sorry i do not know if we are allowed to post links)

Similar Threads

  1. JOptionPane
    By Kazeth in forum What's Wrong With My Code?
    Replies: 4
    Last Post: August 30th, 2014, 12:42 AM
  2. need help in JOptionPane
    By Zuckerberg in forum What's Wrong With My Code?
    Replies: 4
    Last Post: January 28th, 2014, 07:08 AM
  3. JOptionPane error in eclipse
    By runkerr in forum What's Wrong With My Code?
    Replies: 2
    Last Post: July 26th, 2013, 06:09 PM
  4. [SOLVED] Logic error in Math.pow(a,b) using JOptionPane
    By JAKATAK in forum What's Wrong With My Code?
    Replies: 7
    Last Post: February 8th, 2013, 01:18 AM
  5. Error message when using JOptionPane
    By runkerr in forum What's Wrong With My Code?
    Replies: 7
    Last Post: February 5th, 2013, 12:17 PM