0

Why is the confirm dialogue box not working? I have spent forever trying to figure this out. I get the following error:

PokemonDemo.java:40: error: incompatible types: int cannot be converted to String response = JOptionPane.showConfirmDialog(null, "You are a " + intro.getGender() + ". Is that correct?", JOptionPane.YES_NO_OPTION, response);

I have tried changing response to a String (and yes, I used the .equals() method when I did that), but nothing happens. Even when there is not an int in the program, I still get the error. Please let me know if you need my object's code, but I don't see why it would be needed in this case.

public static void main(String [] args)
{
    String holder;
    int response;

    Pokemon intro = new Pokemon();

    JOptionPane.showMessageDialog(null, "Hello there!");
    JOptionPane.showMessageDialog(null, "Glad to meet you!");
    JOptionPane.showMessageDialog(null, "Welcome to the world of Pokémon. My name is Oak.");
    JOptionPane.showMessageDialog(null, "People affectionately refer to me as the Pokémon Professor.");
    JOptionPane.showMessageDialog(null, "For some people, Pokémon are pets. Others use them for battling.");
    JOptionPane.showMessageDialog(null, "As for myself... I study Pokémon as a profession.");
    JOptionPane.showMessageDialog(null, "But first tell me a little bit about yourself...");

    do
    {
        do
        {
            holder = JOptionPane.showInputDialog("Now tell me, are you a boy, or are you a girl?");
            intro.setGender(holder);
        }while(!(intro.getGender().equals("Boy") || intro.getGender().equals("boy") || intro.getGender().equals("BOY") || intro.getGender().equals("Girl") || intro.getGender().equals("girl") || intro.getGender().equals("GIRL")));

        if(intro.getGender().equals("Boy") || intro.getGender().equals("boy") || intro.getGender().equals("BOY"))
        {
            holder = "boy";
            intro.setGender(holder);
        }
        else if(intro.getGender().equals("Girl") || intro.getGender().equals("girl") || intro.getGender().equals("GIRL"))
        {
            holder = "girl";
            intro.setGender(holder);
        }

                 response = JOptionPane.showConfirmDialog(null, "You are a " + intro.getGender() + ". Is that correct?", JOptionPane.YES_NO_OPTION, response);

                 if(response == JOptionPane.NO_OPTION) 
                 {
                     intro.setConfirmationOne("no");
                 } 
                 else if(response == JOptionPane.YES_OPTION) 
                 {
                    intro.setConfirmationOne("yes");
                 } 
    }while(intro.getConfirmationOne().equals("No") ||* intro.getConfirmationOne().equals("no") || intro.getConfirmationOne().equals("NO"));

3 Answers3

0

according to your question:

PokemonDemo.java:40: error: incompatible types: int cannot be converted to String response = JOptionPane.showConfirmDialog(null, "You are a " + intro.getGender() + ". Is that correct?", JOptionPane.YES_NO_OPTION, response);

the showConfirmDialog returns an Integer value, not a String. Change your String response to int response and eval your condition with a integer status (for example, 0 it's Ok, 1 it's Cancel) Read de doc Documentaction

EDIT

Up the incorrectly method, down one of the accepteds

enter image description here

Bye!

Rosendo Ropher
  • 496
  • 8
  • 21
  • See the Chase Henslee answer, your method doesn't match with the JOptionPane's method. You should see something like this `The method showConfirmDialog(Component, Object, String, int) in the type JOptionPane is not applicable for the arguments (null, String, int, int)` – Rosendo Ropher Nov 02 '15 at 19:02
0

I guess your problem is:

response = JOptionPane.showConfirmDialog(null, "You are a " + 
         intro.getGender() + ". Is that correct?", 
         JOptionPane.YES_NO_OPTION, response);

that should be :

response = JOptionPane.showConfirmDialog(null, "You are a " + 
         intro.getGender() + ". Is that correct?", 
         "YOUR TITLE",
         JOptionPane.YES_NO_OPTION, response);

According to javadoc, I guess you are trying to use this method:

public static int showConfirmDialog(Component parentComponent,
                Object message,
                String title, // <-- this is what is missing
                int optionType,
                int messageType)
                         throws HeadlessException
Alex S. Diaz
  • 2,637
  • 2
  • 23
  • 35
0

Your method doesn't match any of the available methods for JOptionPane.

Your options are:

static int showConfirmDialog(Component parentComponent, Object message)

static int showConfirmDialog(Component parentComponent, Object message, String title, int optionType)

static int showConfirmDialog(Component parentComponent, Object message, String title, int optionType, int messageType) 

static int showConfirmDialog(Component parentComponent, Object message, String title, int optionType, int messageType, Icon icon)  

But you use:

JOptionPane.showConfirmDialog(null, String, int, int)

Try changing your method to:

JOptionPane.showConfirmDialog(null, "You are a " + intro.getGender() + ". Is that correct?", "Title", JOptionPane.YES_NO_OPTION);
Chase Henslee
  • 3,918
  • 1
  • 18
  • 21