• 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

Need help in Joining 3 combo boxes

 
Ranch Hand
Posts: 52
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Can any one help me in Joining 3 comboboxes at runtime by using action Listeners

Tha main idea is first I am getting the data for 3 comboboxes (appSet, app, package), and when I select an item in the appSet combo box then the related items should list on the remaining 2 combo boxes for this I added actionListener at getappSetcombobox();

It is executing perfectly and when I select again an item in app combobox list and therelated itemlist should appear in the package combobox

I am not getting this when I am including another actionListener in the getappcombobox();

It is getting NullPointer Exception

I am using the piece of code as follows




I had commented the app action performed method and the actionListener in the getappcombobox();

I am getting NullPointerException because I am using RemoveAllItems in the appSet ActionPerformed method


Please some idea

Thanks in Advance
 
Rancher
Posts: 1337
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
In which line of code are you getting the NPE? Which object is null?
 
Bartender
Posts: 2270
20
Android Java ME Eclipse IDE Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Show us the exception stack trace.
 
Kushi Gadiparthi
Ranch Hand
Posts: 52
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I am getting the error from Line 33


That is

 
Swastik Dey
Bartender
Posts: 2270
20
Android Java ME Eclipse IDE Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator


What happens if anAppList is null? It will throw a NPE in anAppList .size(). So prior to starting the loop make sure that anAppList is not null.
 
Kushi Gadiparthi
Ranch Hand
Posts: 52
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hello Dey,

I uncommented the actionListener in getappcombobox();

and I am getting the error as follows

Exception in thread "AWT-EventQueue-0" java.lang.NullPointerException
at client.cpm.dailyT20.CBRCPMDailyT20View.appComboBox_actionPerformed(CBRCPMDailyT20View.java:243)
at client.cpm.dailyT20.CBRCPMDailyT20View.access$1(CBRCPMDailyT20View.java:241)
at client.cpm.dailyT20.CBRCPMDailyT20View$2.actionPerformed(CBRCPMDailyT20View.java:234)
at javax.swing.JComboBox.fireActionEvent(Unknown Source)
at javax.swing.JComboBox.contentsChanged(Unknown Source)
at javax.swing.JComboBox.intervalRemoved(Unknown Source)
at javax.swing.AbstractListModel.fireIntervalRemoved(Unknown Source)
at javax.swing.DefaultComboBoxModel.removeAllElements(Unknown Source)
at javax.swing.JComboBox.removeAllItems(Unknown Source)
at client.cpm.dailyT20.CBRCPMDailyT20View.appSetComboBox_actionPerformed(CBRCPMDailyT20View.java:194)
at client.cpm.dailyT20.CBRCPMDailyT20View.access$0(CBRCPMDailyT20View.java:190)
at client.cpm.dailyT20.CBRCPMDailyT20View$1.actionPerformed(CBRCPMDailyT20View.java:181)
at javax.swing.JComboBox.fireActionEvent(Unknown Source)
at javax.swing.JComboBox.setSelectedItem(Unknown Source)
at javax.swing.JComboBox.setSelectedIndex(Unknown Source)
at javax.swing.plaf.basic.BasicComboPopup$Handler.mouseReleased(Unknown Source)
at java.awt.AWTEventMulticaster.mouseReleased(Unknown Source)
at java.awt.Component.processMouseEvent(Unknown Source)
at javax.swing.JComponent.processMouseEvent(Unknown Source)
at javax.swing.plaf.basic.BasicComboPopup$1.processMouseEvent(Unknown Source)
at java.awt.Component.processEvent(Unknown Source)
at java.awt.Container.processEvent(Unknown Source)
at java.awt.Component.dispatchEventImpl(Unknown Source)
at java.awt.Container.dispatchEventImpl(Unknown Source)
at java.awt.Component.dispatchEvent(Unknown Source)
at java.awt.LightweightDispatcher.retargetMouseEvent(Unknown Source)
at java.awt.LightweightDispatcher.processMouseEvent(Unknown Source)
at java.awt.LightweightDispatcher.dispatchEvent(Unknown Source)
at java.awt.Container.dispatchEventImpl(Unknown Source)
at java.awt.Window.dispatchEventImpl(Unknown Source)
at java.awt.Component.dispatchEvent(Unknown Source)
at java.awt.EventQueue.dispatchEvent(Unknown Source)
at java.awt.EventDispatchThread.pumpOneEventForFilters(Unknown Source)
at java.awt.EventDispatchThread.pumpEventsForFilter(Unknown Source)
at java.awt.EventDispatchThread.pumpEventsForHierarchy(Unknown Source)
at java.awt.EventDispatchThread.pumpEvents(Unknown Source)
at java.awt.EventDispatchThread.pumpEvents(Unknown Source)
at java.awt.EventDispatchThread.run(Unknown Source)




If I delete the RemoveAll items in appSet actionperformed

then my data in App combobox is overlaping

Please help me
Thank you very much
 
Swastik Dey
Bartender
Posts: 2270
20
Android Java ME Eclipse IDE Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Make sure the following are not null
this.appSetComboBox
this.appComboBox
this.packageComboBox

Because problem seems to be occurring on method calls on these objects.
 
Lester Burnham
Rancher
Posts: 1337
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Once again:

Lester Burnham wrote:In which line of code are you getting the NPE? Which object is null?


You can speed up the process of getting help if you make it a habit to post this crucial information right along with any exception you encounter.
 
Kushi Gadiparthi
Ranch Hand
Posts: 52
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hello Dey

Thanks for quick reply

the problem is I am using the removeAllItems for APP combo box in order to fill the new Items which I had selected from APPSET So I am getting this ERROR

The line is as follows


But If I remove this my data in the APP combo box is overlaping

Can you please suggest an idea because I am struck here and it is very important for me

Thank you very much

 
Kushi Gadiparthi
Ranch Hand
Posts: 52
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hello Lester Burnham,

I am getting the error in the following line


I used this line in order to clear the APP combo box every time when I am selecting an item in the APPSET combo box

and adding the items relating to my selection.

But when I remove this I am not getting the error , but the items in the APP combo box are repeating many times

according to my select

So can you please suggest any idea

It is very urgent

Thank you very much for your reply

Thanks in Advance
 
Swastik Dey
Bartender
Posts: 2270
20
Android Java ME Eclipse IDE Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
this.getAppComboBox().removeAllItems(); is throwing NPE however this.appComboBox.addItem("All Application") is working fine. So what looks to me is appComboBox is getting initialized but there seems to be some problem in the method

 
Kushi Gadiparthi
Ranch Hand
Posts: 52
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hello Swastik Dey,

This is because I am implementing another actionlistener for the second combobox(app)

You can see the code below

I am sorry in the before message I had commented it now you can see the right code and I am also giving the appcombobox_actioPerformed() method also


Because of this actionlistener only I am getting the error






So here in this code again I getting the getAppComboBox()

So it is pointing to the NullPointerException by the this.getAppComboBox.removeAllItems();

I think now you can understand clearly

Please give me any sollution

It is very urgent because I had strucked up here

Thank you very much for spending a lot of time on this issue

Thanks a lot

 
Swastik Dey
Bartender
Posts: 2270
20
Android Java ME Eclipse IDE Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
You get a NPE when you call a method on any null reference. Now lets see the method call
this.getAppComboBox().removeAllItems();
this.getAppComboBox() method is returning a ref to appCombox so one cause of NPE could be appComb is holding a null reference, but that is unlikely because you are initializing that inside that method. So second probability is some exception is occurring inside the getAppComboBox() method. So put some System.out.println message inside the method and see till which is it going properly.
 
Kushi Gadiparthi
Ranch Hand
Posts: 52
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Swastik Dey sir,

But please confirm me one thing that It is right to use actionlisteners for both appSet and app comboboxes,

and the other is I am using Eclipse

So
How can I use System.out.println

I am deploying it by using JBoss
 
Swastik Dey
Bartender
Posts: 2270
20
Android Java ME Eclipse IDE Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I don't think any thing wrong with having separate action listeners for separate objects. But why JBoss, your application seems to be a swing based desktop application, and as far as I know JBoss is needed for web based apps. As far as System.out.println is concerned it should get printed on eclipse console.
 
Kushi Gadiparthi
Ranch Hand
Posts: 52
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Swastik Dey wrote:You get a NPE when you call a method on any null reference. Now lets see the method call
this.getAppComboBox().removeAllItems();
this.getAppComboBox() method is returning a ref to appCombox so one cause of NPE could be appComb is holding a null reference, but that is unlikely because you are initializing that inside that method. So second probability is some exception is occurring inside the getAppComboBox() method. So put some System.out.println message inside the method and see till which is it going properly.



Hello Dey Sir,

I am explaining your doubt by this small code I had first declared combo boxes as follows



and called them as below



and the remaining code for getAppSetComboBox(), getAppComboBox(), getPackageComboBox() methods is known to you as I had send them before

So have a look

Thank you very much

 
Swastik Dey
Bartender
Posts: 2270
20
Android Java ME Eclipse IDE Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Everything fine. But what's wrong in putting few debug messages in that method and see whether the function is behaving properly or not.
 
Kushi Gadiparthi
Ranch Hand
Posts: 52
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hello Swastik Dey Sir,

Can You please tell me how to do this because I am using Eclipse for the first time

Thank you very much,
 
Swastik Dey
Bartender
Posts: 2270
20
Android Java ME Eclipse IDE Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Place your cursor on the first line of the method. Now under Run menu you will find an option as toggle break point. Click on that. Now again from Run menu click debug, now your application will run under debug mode and it will halt the execution when the control comes to that line the program execution will halt. Now press F6 for step by step execution. I hope you will be able to find which line is causing the problem.
 
Kushi Gadiparthi
Ranch Hand
Posts: 52
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Swastik Dey Sir,

Hello Sir , I got the data, and my errors are removed,

So thank you very much for your help,

I had just implemented a piece of code like this



So it had worked for me perfectly,

Thank you very much for your help,
 
Swastik Dey
Bartender
Posts: 2270
20
Android Java ME Eclipse IDE Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Jashvika,

You are most welcome.
 
Don't get me started about those stupid light bulbs.
reply
    Bookmark Topic Watch Topic
  • New Topic