• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

Help with DefaultComboBoxModel

 
Ranch Hand
Posts: 33
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
 
Ranch Hand
Posts: 15304
6
Mac OS X IntelliJ IDE Chrome
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
 
With a little knowledge, a cast iron skillet is non-stick and lasts a lifetime.
reply
    Bookmark Topic Watch Topic
  • New Topic