Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/java/346.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
jGrasp Java字符串到布尔错误!“ClientID.java:20:错误:不兼容的类型:无法将字符串转换为布尔值”_Java_Jgrasp - Fatal编程技术网

jGrasp Java字符串到布尔错误!“ClientID.java:20:错误:不兼容的类型:无法将字符串转换为布尔值”

jGrasp Java字符串到布尔错误!“ClientID.java:20:错误:不兼容的类型:无法将字符串转换为布尔值”,java,jgrasp,Java,Jgrasp,我有这行代码,我有问题 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

我有这行代码,我有问题

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\".   ");
我得到了不兼容类型的错误,因为我在nameCheck行中有一个布尔字符串,但我只希望在name中输入的名称出现在nameCheck的文本中,以便用户检查他们输入的内容是否正确。 但是我不知道如何在布尔对话框窗口中合并名称enter,这样,如果名称正确,他们就可以键入true;如果名称不正确,他们就可以键入false,这将把他们带到行中

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 Admin_Med@clinic.ae; \n Client Name: "+name); 
     }
这样,如果他们在开始时出错,就可以重新键入希望保存的名称

但我仍然面临错误问题:不兼容类型:字符串无法转换为布尔值。showInputDialog返回一个包含用户输入的字符串,这意味着如果要检查用户输入的是真是假,则必须解析他们输入的内容,如下所示:

boolean b = nameCheck.equalsIgnoreCase("true");
如果用户输入true,则将布尔值设置为true,否则设置为false

编辑:也可以使用Boolean.valueOfString s