I try to cast a ComboBox.SelectedItem() to int and it isn’t working. I know that ComboBox.SelectedItem() has the type String and I casted it like this:
int idprovider = ((Integer)IdProviderComboBox.getSelectedItem()).intValue();
but I get the error:
java.lang.ClassCastException: java.lang.String cannot be cast to java.lang.Integer
Maybe someone has an idea.
Thanks!
You are casting String to Integer hence its throwing ClassCastException, to get int out of a String use one of the following:
Update:
JComboBox.getSelectedItem() will return you Object, to covert it to int use :