Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

The type JComboBox is not generic; it cannot be parameterized with arguments <Object>

Tags:

java

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?

like image 624
sandra Avatar asked Jun 21 '13 11:06

sandra


2 Answers

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

like image 196
Suresh Atta Avatar answered Nov 03 '22 01:11

Suresh Atta


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.

like image 43
Reimeus Avatar answered Nov 03 '22 00:11

Reimeus