1

I have this line of Code, which i am having problems with.

name = (JOptionPane.showInputDialog("What is the name of the new Client? \n (Format) \" Jake Michael Drewberg\"  "));
nameCheck= JOptionPane.showInputDialog("Please check that this is correct: "+name+". \n If this is correct please enter \"true\". if not enter \"false\".   ");

i Get the error of incompatible types because I have the String inside the nameCheck line which is a boolean, but i just want the name entered in "name" to appear in the text of nameCheck for the user to check that what they have entered is actually correct. But i don't know how to incorporate the name enter in the boolean Dialog window so that they can type true if the name is correct or false if it is not correct which will then take them to the line

if (nameCheck==false)
     {
        name = JOptionPanel.showInputDialog("Please enter the full name of the Client with the first letter of each name in Capital letters. ");  
        System.out.println("This is the final name being saved to our files, if any further issue present themselves please reffer to our Admin staff at [email protected]; \n Client Name: "+name); 
     }

so that they can Retype the name they want saved if they made a mistake in the beginning.

but i still sit with the problem of "error: incompatible types: String cannot be converted to boolean"

0

1 Answer 1

0

JOptionPane.showInputDialog() returns a String containing the user's input, meaning if you want to check that the user entered true or false, you'd have to parse what they entered, like so:

boolean b = nameCheck.equalsIgnoreCase("true");

This will set the boolean to true if the user entered true, false otherwise.

EDIT: You can also use Boolean.valueOf(String s)

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.