• 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

How to handle more than two combobox

 
Greenhorn
Posts: 22
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi,

I have 4 combo box and m adding values to combo box depending on previous combo box value.
n when user selects another value in same combo box i just called removeAllItems(); on combo box.so that previous values gets deleted. .it is working for only 2 combo boxes.
but it gives null pointer exception for more than 2 combo box. This is because when i called removeallItems() then actionlister is called automatically. n i hav written query for adding values to that in actionlistener.
so how should i handle these combo boxes??
thanks in advance...
 
Bartender
Posts: 563
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Can you show some code?
 
Swela Jathar
Greenhorn
Posts: 22
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Thanks Greq,

see I have combo boxs for Person Name,Person Id,and Receipt No.

I have added person names to combo in constructor.



Next In ActionListener of first combo box i hav added customer id into 2nd combo box.
like


up to this it is working fine...then according to customer id i wants to select receipt no.
so in actionlistener of 2nd combo box i hav written code like



I got Null pointer exception..


 
Bartender
Posts: 11497
19
Android Google Web Toolkit Mac Eclipse IDE Ubuntu Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Where have you initialized combo_receipt_report?
 
Swela Jathar
Greenhorn
Posts: 22
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
thanks maneesh,
I have just added an item like "select report" in constructor...


Main problem is that when i remove items from combo_receipt_report in combo_person_idActionPerformed (LINE NO 4) then actionlistener of combo_receipt_report is called.thats why it is giving null pointer exception..

Thanks...
 
Bartender
Posts: 1104
10
Netbeans IDE Java Ubuntu
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
That indicates a problem in the actionListener code of combo_receipt_report. Based on your other actionListeners, I am thinking you are making a call to: in the actionListener of that combo. Instead you should add a null check. When all the items are removed, there is no item to select - so the getSelectedItem() will return null.
 
Maneesh Godbole
Bartender
Posts: 11497
19
Android Google Web Toolkit Mac Eclipse IDE Ubuntu Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Swela Jathar wrote:thanks maneesh,
I have just added an item like "select report" in constructor...


Main problem is that when i remove items from combo_receipt_report in combo_person_idActionPerformed (LINE NO 4) then actionlistener of combo_receipt_report is called.thats why it is giving null pointer exception..

Thanks...



I don't think you are understanding what I am saying. Have you initialized combo_receipt_report? Something like combo_receipt_report=new JComboBox()
 
Swela Jathar
Greenhorn
Posts: 22
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
ya..i hav initialized it...n then added item to it..
 
Maneesh Godbole
Bartender
Posts: 11497
19
Android Google Web Toolkit Mac Eclipse IDE Ubuntu Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
With the code you have posted till now it is difficult to say what's going wrong. You can help us help you better by posting a SSCCE code. Please do take out time to click the SSCCE link to find out what it really means.
 
Greenhorn
Posts: 7
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi friends,

I also face the same problem.

Can you please help me in details?
 
Swela Jathar
Greenhorn
Posts: 22
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi Maneesh,

can you show me some another example which handles more than three combo boxes?
Thanks..
 
Consider Paul's rocket mass heater.
reply
    Bookmark Topic Watch Topic
  • New Topic