Skip to Main Content

Java Programming

Announcement

For appeals, questions and feedback about Oracle Forums, please email oracle-forums-moderators_us@oracle.com. Technical questions should be asked in the appropriate category. Thank you!

Problems casting an object from a combo box

807588Mar 9 2009 — edited Mar 9 2009
I have a combo box and I'm adding an object called haplotype and overriding the toString method to display the name of the object like this:
cmb.addItem(new tables.Haplotype ( rs.getInt("HTY_HAPLOTYPE_ID"),rs.getString("HTY_TEXT")));
It gets the id of the haplotype and the name from a database and adds it to a combo box.

The problem I'm having is that when I try to update the object to the database I get the following error message:

from this line of code
tables.Haplotype h1 = (tables.Haplotype) HLA_Haplotype1Cmb.getSelectedItem();
Exception in thread "AWT-EventQueue-0" java.lang.ClassCastException: java.lang.String cannot be cast to tables.Haplotype

This is making me totally confused, since I'm sure I'm adding the Haplotype object to the combo box. Is it possible that it's adding a string in some cases?
Comments
Locked Post
New comments cannot be posted to this locked post.
Post Details
Locked on Apr 6 2009
Added on Mar 9 2009
6 comments
195 views