简体   繁体   English

非法开始类型错误

[英]Illegal start of type error

Could someone please help me with this? 有人可以帮我吗? I'm having an error illegal start of type error in the line }); 我在})行​​中有一个错误非法的类型错误开始。 I am very confused on how to fix this. 我对如何解决此问题感到非常困惑。 Any help will be extremely appreciated. 任何帮助将不胜感激。 The codes are below: 代码如下:

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

Your ); 您的); is misplaced: it should be after the } on the next line: 放错了位置:应该在下一行的}之后:

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

Change your code from 从更改您的代码

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

to

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

do this 做这个

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

instead of this: 代替这个:

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

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM