aspose file tools*
The moose likes Applets and the fly likes Need help in Joining 3 combo boxes Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Spring in Action this week in the Spring forum!
JavaRanch » Java Forums » Java » Applets
Bookmark "Need help in Joining 3 combo boxes" Watch "Need help in Joining 3 combo boxes" New topic
Author

Need help in Joining 3 combo boxes

Kushi Gadiparthi
Ranch Hand

Joined: Sep 23, 2010
Posts: 52
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


Jashvika
Lester Burnham
Rancher

Joined: Oct 14, 2008
Posts: 1337
In which line of code are you getting the NPE? Which object is null?
Swastik Dey
Rancher

Joined: Jan 08, 2009
Posts: 1477
    
    6

Show us the exception stack trace.


Swastik
Kushi Gadiparthi
Ranch Hand

Joined: Sep 23, 2010
Posts: 52
I am getting the error from Line 33


That is

Swastik Dey
Rancher

Joined: Jan 08, 2009
Posts: 1477
    
    6



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
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
Rancher

Joined: Jan 08, 2009
Posts: 1477
    
    6

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
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
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
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
Rancher

Joined: Jan 08, 2009
Posts: 1477
    
    6

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
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
Rancher

Joined: Jan 08, 2009
Posts: 1477
    
    6

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
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
Rancher

Joined: Jan 08, 2009
Posts: 1477
    
    6

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
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
Rancher

Joined: Jan 08, 2009
Posts: 1477
    
    6

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

Joined: Sep 23, 2010
Posts: 52
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
Rancher

Joined: Jan 08, 2009
Posts: 1477
    
    6

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
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
Rancher

Joined: Jan 08, 2009
Posts: 1477
    
    6

Jashvika,

You are most welcome.
 
 
subject: Need help in Joining 3 combo boxes