开发者

Nested If Statements FAILing

I am coming from a C background, so I am assuming I have the syntax incorrect.

In the following code;

    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("");
            }

       开发者_Go百科 } //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

I am getting compile errors saying "} Unexpected on line X, and premature EOF. If I removed the sub IFs that evalute map.containsKey(Id) it compiles and runs fine. Everything I read on the internet says Java is capable of nesting IF statements, so what exactly am I doing wrong?

Thanks for your help!

CJ


This line?

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

Your method call is not closed. I think you meant to do this:

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


Your problem is in the last else if statement:

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

This line is not closed. Like a previous poster said, you should do something like,

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

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜