16
String[] boxOptions = {"1","2","4","8","16","20","40","100","400"};
JComboBox box = new JComboBox(boxOptions);

I had these exact lines of code in my program before, and wasn't getting this error. I did a bit of searching and the results I found are going a bit over my head. Any ideas?

The error is:

JComboBox is a raw type. References to generic type JComboBox<E> should be parameterized
Andrew Thompson
  • 168,117
  • 40
  • 217
  • 433
tssguy123
  • 185
  • 1
  • 1
  • 9

2 Answers2

34

You can use:

JComboBox<String> box = new JComboBox<>(boxOptions);

This happens because JComboBox is now a generic class.

BobTheBuilder
  • 18,858
  • 6
  • 40
  • 61
7

As of Java 7, generics were introduced into JComboBox component. Maybe you were using Java6 before. You should add JComboBox<String> to the second line there.

britulin
  • 310
  • 2
  • 4