I need to remove all items from the combo box
int itemCount = combo.getItemCount();
for(int i=0;i<itemCount;i++){
combo.removeItemAt(0);
}
This code will remove all items except the last one. It gives a NullPointerException. How to fix that?
The code in the question would normally work. However, it looks like a threading issue. Another thread may be messing with the items.
However, I sugeest you should better use the removeAllItems();
method:
combo.removeAllItems();