Search code examples
javacompiler-errorsjcombobox

Error: unchecked call to DefaultComboBoxModel(E[])


When I build / run my applet, made from the NetBeans Applet Form I get 2 errors:

warning: [unchecked] unchecked call to DefaultComboBoxModel(E[]) as a member of the raw type DefaultComboBoxModel
        levelBox.setModel(new javax.swing.DefaultComboBoxModel(new String[] { "1", "2", "3", "4", "5", "6", "7" }));
  where E is a type-variable:
    E extends Object declared in class DefaultComboBoxModel
warning: [unchecked] unchecked call to setModel(ComboBoxModel<E>) as a member of the raw type JComboBox
        levelBox.setModel(new javax.swing.DefaultComboBoxModel(new String[] { "1", "2", "3", "4", "5", "6", "7" }));
  where E is a type-variable:
    E extends Object declared in class JComboBox
2 warnings

If I click on the dropdown I get an exclamation mark next to it. Why is that?

Also, this is with the "-Xlint:unchecked" option.


Solution

  • new javax.swing.DefaultComboBoxModel(new String[]
    

    should be replaced by

    new javax.swing.DefaultComboBoxModel<String>(new String[]
    

    This warning can be ignored as well.