I have an editable
JComboBox
which is integrated with the AutoCompleteDecorator
of SwingX
library. My JComboBox
is also having an ItemListener
registered to it as well. Now, Please have a look at the below code.
AutoCompleteDecorator.decorate(ClientNameCombo);
ClientNameCombo.addItemListener(new ClientNameComboAction());
private class ClientNameComboAction implements ItemListener
{
@Override
public void itemStateChanged(ItemEvent e)
{
String selectedClientName= ClientNameCombo.getSelectedItem().toString();
if(!selectedClientName.equals("Select Client"))
{
int idClient = Integer.parseInt(String.valueOf(client_name_id_map.get(selectedClientName)));
String sql = "r";
}
}
}
No matter what, my code do not pass int idClient = Integer.parseInt(String.valueOf(client_name_id_map.get(selectedClientName)));
it always ended up with NumberFormatException
. The amazing thing is, if I remove AutoCompleteDecorator
then everything works fine.
Anyone know how to fix this please?
The problem would occur when the key you are looking for is not found in the map.
In such case :
client_name_id_map.get(selectedClientName)
would return nullString.valueOf(client_name_id_map.get(selectedClientName))
would return "null"Integer.parseInt("null")
would throw an exceptionA simple solution :