Win a copy of Kotlin in Action this week in the Kotlin forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic

Help with DefaultComboBoxModel  RSS feed

 
Andrew McLaren
Ranch Hand
Posts: 33
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I am having serious problems with using DefaultComboBoxModel. My basic goal is to have a combo box that shows one value, and uses another, that refreshes after a button is clicked. When I try to add an element to the DefaultComboBoxModel, I am getting a null pointer exception, and I don't understand why.

for (int i=0;i<reports.length;i++) {
lstReports.add(reports[i].getSearchPath().getValue());
cbItems = new CBItem[reports.length];
cbItems[i] = new CBItem(reports[i].getDefaultName().getValue(),reports[i].getSearchPath().getValue());
System.out.println("item: " + cbItems[i].toString());
testModel.addElement(cbItems[i]);

}
The print statement works fine, so I know that cbItems[i] is valid. But I crash at the addElement line.
What am I missing here? (I should probably mention that I am very new to using Swing)

Thanks!

Andrew
 
Gregg Bolinger
Ranch Hand
Posts: 15304
6
Chrome IntelliJ IDE Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
My first guess is the possibility that your testModel object is null. Do you know for a fact that you have instantiated this testModel object before this code is executed?
 
Andrew McLaren
Ranch Hand
Posts: 33
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Originally posted by Gregg Bolinger:
My first guess is the possibility that your testModel object is null. Do you know for a fact that you have instantiated this testModel object before this code is executed?



Ooooh how embarassing... I did instatiate it, but for this particular block it was out of scope. Don't know if I ever would have thought of that, I was so convinced I was doing something wrong specific to DefaultComboBoxModel.

Thanks!

Andrew
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!