当前位置: 首页 > 知识库问答 >
问题:

jgraph Java字符串到布尔错误!“Clientid.java:20:错误:不兼容的类型:String无法转换为Boolean”

公沈浪
2023-03-14
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\".   ");
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); 
     }

但我仍然对“错误:不兼容的类型:String无法转换为Boolean”这个问题深信不疑。

共有1个答案

符懿轩
2023-03-14

joptionpane.showInputDialog()返回一个包含用户输入的字符串,这意味着如果您想检查用户输入的是true还是false,您必须解析他们输入的内容,如下所示:

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

如果用户输入true,则将布尔值设置为true,否则设置为false。

编辑:还可以使用boolean.valueOf(String s)

 类似资料: