1

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);
}
Andreas Fester
  • 36,091
  • 7
  • 95
  • 123

3 Answers3

4

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
Sergey Kalinichenko
  • 714,442
  • 84
  • 1,110
  • 1,523
1

Change your code from

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

to

}  // I am getting an error in this line
});
 ^
Achrome
  • 7,773
  • 14
  • 36
  • 45
0

do this

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

instead of this:

});  // I am getting an error in this line
}
codeMan
  • 5,730
  • 3
  • 27
  • 51