• Post Reply Bookmark Topic Watch Topic
  • New Topic

Getting [unchecked] error when compiling using sdk  RSS feed

 
Greenhorn
Posts: 5
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
This has to be the first time I have ever seen this error message. I get this when trying to compile the program using javac, (1.7.0), and I had to use -Xlint:unchecked to find out the error which is below:


"Week4Individ2.java:55: warning: [unchecked] unchecked call to addItem<E> as a member of the raw type JComboBox.

I am not getting errors in my other Array that I have setup;




aptCombo is the JComboBox and is declared as followed;



The portion of code this is occuring is here






It says where E is a type-variable: E extends Object Declared in class JComboBox.

It runs and populates to the combobox perfectly in NetBeans, however I am quite thankful I tried to compile the same using javac. This is causing me a headache trying to figure out a work around. Any information would be helpful as I attempt to fix this issue.
 
Ranch Hand
Posts: 75
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi Mike,

You have to use generics with Java 1.7's JComboBox.

Try following -
 
Ranch Hand
Posts: 73
Android Java Netbeans IDE
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi Mike,

First things first...
public void addItem(E item)
Adds an item to the item list. This method works only if the JComboBox uses a mutable data model.

I guess the problem in your case is that you haven't specified what type of objects the JComboBox will house as you haven't used any generics. So it goes without saying the default will be Object.
Now you are trying to add String to JComboBox where as it is expecting Object so compilation fails.

Try using something like this,


Tell me if it works!
Hope this helps.
 
Mike Rahok
Greenhorn
Posts: 5
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thanks So Much!! I am in shock that was the issue.. I really appreciate the help and fast feedback! The application works great now that I can compile it .
 
Sheriff
Posts: 21135
87
Chrome Eclipse IDE Java Windows
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Also note that you never got an error in the first place. It was a warning instead. Your class still compiled just fine.
 
Marshal
Posts: 56600
172
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
You can read about generics in the Java Tutorials (there are actually two generics sections).
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!