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
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
Joined: Sep 23, 2010
Posts: 52
posted
0
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
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
Joined: Oct 14, 2008
Posts: 1337
posted
0
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
Joined: Sep 23, 2010
Posts: 52
posted
0
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
Joined: Sep 23, 2010
Posts: 52
posted
0
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
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
Joined: Sep 23, 2010
Posts: 52
posted
0
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
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
Joined: Sep 23, 2010
Posts: 52
posted
0
Swastik Dey sir,
But please confirm me one thing that It is right to use actionlisteners for both appSet and app comboboxes,
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
Joined: Sep 23, 2010
Posts: 52
posted
0
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
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
Joined: Sep 23, 2010
Posts: 52
posted
0
Swastik Dey Sir,
Hello Sir , I got the data, and my errors are removed,