1

誰かがこれで私を助けてくれますか? 行に不正なタイプの開始エラーがあります }); これを修正する方法について非常に混乱しています。どんな助けでも大歓迎です。コードは以下のとおりです。

public SubokUlit(){
    String mgaPagkainTo[] = {"PM1 (Paa/ Spicy Paa with Thigh part)","PM2 (Pecho)","PM3 (Pork Barbeque 4 pcs.)","PM4 (Bangus Sisig)","PM5 (Pork Sisig)","PM6 (Bangus Inihaw)","SM1 (Paa)","SM2 (Pork Barbeque 2 pcs.)","Pancit Bihon","Dinuguan at Puto","Puto","Ensaladang Talong","Softdrinks","Iced Tea","Halo-Halo","Leche Flan","Turon Split"};
    JFrame frame = new JFrame("Mang Inasal Ordering System");
    JPanel panel = new JPanel();
    combo = new JComboBox(mgaPagkainTo);
    combo.setBackground(Color.gray);
    combo.setForeground(Color.red);
    panel.add(combo);
    frame.add(panel);

    combo.addActionListener(new ActionListener(){
        public void actionPerformed(ActionEvent e){
            String str = (String)combo.getSelectedItem();
            a = str;
            if(a == "PM1 (Paa/ Spicy Paa with Thigh part)"){
                Wew();
            }
            else if(a == "PM2 (Pecho)"){
                Wew1(); 
            }
        });  // I am getting an error in this line
    }

    frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
    frame.setSize(300,100);
    frame.setVisible(true);
}
4

3 に答える 3

4

あなたの場所が間違っています:次の行の の);後にある必要があります:}

combo.addActionListener(new ActionListener(){
    public void actionPerformed(ActionEvent e){
        String str = (String)combo.getSelectedItem();
        a = str;
        // Comparing strings should use equals, not ==
        if(a.equals("PM1 (Paa/ Spicy Paa with Thigh part)")){
            Wew();
        } else if(a.equals("PM2 (Pecho)")){
            Wew1(); 
        }
    } // <<== Not here: this brace ends the method
}); // <<== It should be after the brace that ends the anonymous class
于 2013-03-05T10:42:47.030 に答える
1

コードを次から変更します

});  // I am getting an error in this line
}

}  // I am getting an error in this line
});
 ^
于 2013-03-05T10:43:28.780 に答える
0

これを行う

}  // I am getting an error in this line
});

これの代わりに:

});  // I am getting an error in this line
}
于 2013-03-05T10:44:35.497 に答える