gpt4 book ai didi

java - 嵌套 If 语句失败

转载 作者:行者123 更新时间:2023-12-01 07:39:04 26 4
gpt4 key购买 nike

我有 C 背景,所以我假设我的语法不正确。

在下面的代码中;

    public class ButtonListener implements ActionListener {
public void actionPerformed(ActionEvent e) {

String jcbValue = (String) jcbIDF.getSelectedItem();
if (jcbValue.equals("Insert")) {

String Id = jtfId.getText();
ArrayList<String> ValueList = new ArrayList<String>();
String Name = jtfName.getText();
String GPA = jtfGPA.getText();
ValueList.add(Name);
ValueList.add(GPA);
if (map.containsKey(Id)){
JOptionPane.showMessageDialog(null, "Key exists!",
"Result", JOptionPane.INFORMATION_MESSAGE);
}
else if (!map.containsKey(Id)){

map.put(Id, ValueList);
System.out.println(map);

JOptionPane.showMessageDialog(null, "Record inserted",
"Result", JOptionPane.INFORMATION_MESSAGE);
jtfId.setText("");
jtfName.setText("");
jtfGPA.setText("");
}

} //terminates insert
else if (jcbValue.equals("Delete")) {
String Id = jtfId.getText();
ArrayList<String> ValueList = new ArrayList<String>();
String Name = jtfName.getText();
String GPA = jtfGPA.getText();

if (map.containsKey(Id)){
JOptionPane.showMessageDialog(null, "Key exists, deleted!",
"Result", JOptionPane.INFORMATION_MESSAGE);
} else if (!map.contasKey(Id)){
System.out.println(map);
JOptionPane.showMessageDialog(null, "Key Does not exist!",
}


} //terminates delete
else if (jcbValue.equals("Find")) {
System.out.println(map);
JOptionPane.showMessageDialog(null,
"Find Selected; But not Implemented", "Result",
JOptionPane.INFORMATION_MESSAGE);
} //terminates find

}// Terminates actionPerformed Class
}// Terminates ButtonListenerClass

我收到编译错误,提示“} Unexpected on line X, and过早的 EOF。如果我删除了评估 map.containsKey(Id) 的子 IF,它会编译并运行良好。我在互联网上读到的所有内容都说 Java 是有能力的嵌套 IF 语句,那么我到底做错了什么?

感谢您的帮助!

CJ

最佳答案

这一行?

        JOptionPane.showMessageDialog(null, "Key Does not exist!",
}

您的方法调用未关闭。我认为你的意思是这样做:

        JOptionPane.showMessageDialog(null, "Key Does not exist!",
"Result", JOptionPane.INFORMATION_MESSAGE);
}

关于java - 嵌套 If 语句失败,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/7785243/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com