I have a code for my project in Java and one of the classes is as shown below but when I want to run this code I will get compile error in this class one part of code is:
package othello.view;
import java.awt.BorderLayout;
import java.awt.Container;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import javax.swing.BorderFactory;
import javax.swing.BoxLayout;
import javax.swing.JButton;
import javax.swing.JComboBox;
import javax.swing.JFrame;
import javax.swing.JLabel;
import javax.swing.JPanel;
import javax.swing.border.Border;
import javax.swing.border.EmptyBorder;
import othello.ai.ReversiAI;
import othello.controller.AIControllerSinglePlay;
import othello.controller.AIList;
import othello.model.Board;
import othello.model.Listener;
@SuppressWarnings("serial")
public class TestFrameAIVSAI extends JFrame implements ActionListener, Logger,
Listener {
private static Border THIN_BORDER = new EmptyBorder(4, 4, 4, 4);
public JComboBox<Object> leftAICombo;
public JComboBox<Object> rightAICombo;
private JButton startTest;
private JButton pauseTest;
The error is from the two lines public JComboBox<Object> leftAICombo;
and public JComboBox<Object> rightAICombo;
and the error is:
The type JComboBox is not generic; it cannot be parameterized with arguments <Object>
What is the problem?
Change the below lines
public JComboBox<Object> leftAICombo;
public JComboBox<Object> rightAICombo;
to
public JComboBox leftAICombo;
public JComboBox rightAICombo;
Here JComboBox<Object>
type parameter introduced in java7 only.if you are using jdk below 7 it gives error
Generics were added to JComboBox
in Java 7. It appears you are using an eariler version of the JDK. Either upgrade to Java 7 or remove the generics. The former is recommended as it offers more features/fixes as well as being up-to-date.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With