Cry*_*nes 0 java generics if-statement
我来自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
Run Code Online (Sandbox Code Playgroud)
我收到编译错误说"}在X行上意外,并且过早的EOF.如果我删除了评估map.containsKey(Id)的子IF,它编译并运行正常.我在互联网上读到的所有东西都说Java能够嵌套IF陈述,那我究竟做错了什么?
谢谢你的帮助!
CJ
这行?
JOptionPane.showMessageDialog(null, "Key Does not exist!",
}
Run Code Online (Sandbox Code Playgroud)
您的方法调用未关闭.我想你打算这样做:
JOptionPane.showMessageDialog(null, "Key Does not exist!",
"Result", JOptionPane.INFORMATION_MESSAGE);
}
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
320 次 |
| 最近记录: |