I have created an application that uses two comboboxes, one for the states and one for the cities. The cities will be populated after the state has been chosen. It all works fine until I try to go back and choose another state. When I pick another state a NullPointerException is thrown at the call to JComboBox.removeAllItems(). Can someone enlighten me to the problem and/or a possible workaround? Thanks! -Eric
Re: NullPointerException using JComboBox.removeAllItems()
Jun 13, 2006 8:09 AM
(reply 4
of 4) (In reply to
#1 )
This solved my problem too, and I am using JDK 1.5 (so it's not just an older JDK issue).
Incidentally, some other forums indicated that this occurs only when the JComboBox getItemCount returns 0 and you try to issue removeAllItems(). However, guarding against a zero item count didn't fix my problem, whereas this post's "setModel" approach did.
Also using invokeLater() to set up the GUI didn't fix it either, something I initially though was it because the problem went away if I sat on the same line in the debugger for 5 seconds or so before proceeding forward.
Thanks--your post was very helpful to me.
(Is this deleteAllItems() behaviour considered to be bug in the JDK?)