Are you asking for help with the second listener? If so, you need to show me the code!

Hello James Sir,

I am giving the code for the second actionlistener,

I had included the second actionlistener in the getappComboBox()
You can see it below

So it is gving the NPE error which I told you before

But when I delete the this.getAppComboBox.removeAllItems();

in the appSet_actionPerformed() method , it is working and I am getting the data for the package combobox based on the selection in App combo but the data in the App combo is repeating many times this is the problem.

public JComboBox getAppComboBox() {			
		if (this.appComboBox == null) {
			this.appComboBox = new JComboBox();
			// Populate the App list
			this.appComboBox.addItem("All Application");
			ArrayList<String> anAppList = CBRCPMDailyT20AppManager.instance()
					.getAppList();
			for (int j = 0; j < anAppList .size(); j++) {
				this.appComboBox.addItem(anAppList .get(j));
			}	
			[B] this.appSetComboBox.removeActionListener(appSetComboBox);
	 		 this.appComboBox.addActionListener(new ActionListener() {
 
				public void actionPerformed(ActionEvent eventpack) {
					appComboBox_actionPerformed(eventpack);
				}
			});[/B]		}
		return this.appComboBox;
	}


private void appComboBox_actionPerformed(ActionEvent eventpack) {		
		//String appSet = "AMADEUS_CPM";
		String app = this.getAppComboBox().getSelectedItem().toString();
		this.appComboBox.setSelectedItem(app);		
		this.getPackageComboBox().removeAllItems();
		this.packageComboBox.addItem("All Package");
		ArrayList<String> anPackageList = CBRCPMDailyT20AppManager.instance()
				.getPackageListapp(app);//replace by app
		for (int j = 0; j < anPackageList.size(); j++) {
			this.packageComboBox.addItem(anPackageList.get(j));
		}
		this.packageComboBox.setSelectedIndex(0);
	}

please give me some Idea to get out of this issue

Thank you very much

So this is exactly the same problem that you have (had?) with the first listener?
Do you still have that problem with the first listener?
You seem to have ignored everything I said about that, so I'm not going to say it all again.

Hello James Sir,

This is problem what I am saying from first onwards

But you said me not to load the data for the first and load the data at runtime

But it is not possible for me , I had to display the data first and again add action listeners,

So please give me an idea in this,

Thnk you very much

You never answered my post 2 days ago

One last time before I move on to something else...
why are using getAppComboBox() instead of just referring to appComboBox like you do on the next line? It can't be what you told me earlier - "give the list of items for the app combo box" - because the very next thing you do is to remove all the contents anyway.

Sorry Sir I did not understand this can you please explain me


Thanks

Why do you have

String app = this.getAppComboBox().getSelectedItem().toString();
		this.appComboBox.setSelectedItem(app);		
		this.getPackageComboBox().removeAllItems();
		this.packageComboBox.addItem("All Package");

and not

String app = this.getAppComboBox().getSelectedItem().toString();
		this.appComboBox.setSelectedItem(app);		
		this.packageComboBox.removeAllItems();
		this.packageComboBox.addItem("All Package");

I am using that to just get the selected items of AppComboBox.

I am using the same in AppSet combo box also

String appSet = this.getAppSetComboBox().getSelectedItem().toString();		
		//String appSet = "AMADEUS_ABG";		this.appSetComboBox.setSelectedItem(appSet);				this.getAppComboBox().removeAllItems();		
         this.getPackageComboBox().removeAllItems();

This is to get the item which is selected in the AppSet combo box and it is stored in appSet which is declared as String

Yes yes yes, I know that. I asked why you used the first version of the code, not the second version that I showed you. Why do you think I asked you a question? If you don't want to answer it, just tell me and I'll go away.

Why do you have

String app = this.getAppComboBox().getSelectedItem().toString();
		this.appComboBox.setSelectedItem(app);		
		this.getPackageComboBox().removeAllItems();
		this.packageComboBox.addItem("All Package");

and not

String app = this.getAppComboBox().getSelectedItem().toString();
		this.appComboBox.setSelectedItem(app);		
		this.packageComboBox.removeAllItems();
		this.packageComboBox.addItem("All Package");

Sorry Sir James Sir now I had understood Perfectly

I am using that just to removeall Items in the package combo

and I think it would not work for just packagecombobox.removeAllItems(),

and it will give error for me because packageComboBox it not a method

and also I had to check whether it works for just this.packageComboBox.RemoveAllItems()

than this.getpackageComboBox.RemoveallItems()

Any way thank you very much for pointing out to me

and please tell If I need to change more because the problem is this already a built in project and I am using the same code to do modifications and fro creating new screens

Very very thanks for spending a lot of time

Thank you very much

and that is not the code written by me

I think it would not work for just packagecombobox.removeAllItems(), and it will give error for me because packageComboBox it not a method

I can see no reason why that would not work. Did you try it?

Yes yes yes, I know that. I asked why you used the first version of the code, not the second version that I showed you. Why do you think I asked you a question? If you don't want to answer it, just tell me and I'll go away.

Hello Sir,

Don´t think like that ,

once again I am answering,

It is not the code written by me

and I don´t know why thet are used getAppComboBox() instead of appComboBox()

and you had ponted to me a good question to investigate

and tomrrow I will investigate it answer you what is happening between these changes of code

thanks

but don´t miss understand me

because I am asking a help and for understandng purpose I had to give the full code and everything what you need to help me

Thanks

OK, but don't confuse the variables and the methods. It's not appComboBox() it's just appComboBox - it's a variable not a method.
I want you to try that because:
You want to remove the items from the existing appComboBox, and the obvious syntax to do that is
appComboBox.removeAllItems();
If you use getAppComboBox().removeAllItems();
that creates a new combo box, and has side effects, whiuch MAY be the cause of your problem

I can see no reason why that would not work. Did you try it?

No sir I did not try it


I wiil try tomarrow and give you answer

Thank You Sir,

Hello James Sir,

I had tried it but there is no use it is giving me the same NPE error,

I modified the code as follows

this.appSetComboBox.setSelectedItem(appSet);		
this.appComboBox.removeAllItems();
String app = this.appComboBox.getSelectedItem().toString();
		this.appComboBox.setSelectedItem(app);

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:259)
at client.cpm.dailyT20.CBRCPMDailyT20View.access$1(CBRCPMDailyT20View.java:255)
at client.cpm.dailyT20.CBRCPMDailyT20View$2.actionPerformed(CBRCPMDailyT20View.java:244)
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:196)
at client.cpm.dailyT20.CBRCPMDailyT20View.access$0(CBRCPMDailyT20View.java:192)
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)

,

Please see this

Thnaks

OK, now I see the whole error stack I can see something very interesting.
I have a theory.
In appSetComboBox_actionPerformed you remove all items from the app combo box.
This changes the state of that combo box, which fires an action event.
Your action event handler for the app combo box is called immediately.
That handler calls getSelectedItem() - which returns null because there are no items (you just removed them all).
You then call toString() on that, and get an NPE.

In other words it's not the removeAllItems() that's giving the NPE, it's the handler for the event that's generated by removing the items.

IF I'm right then you need to test for a null selected item. If it is null you can just return from the handler because there's nothing else for you to do.
Try changing BOTH action event handlers to replace the line like this

String app = this.getAppComboBox().getSelectedItem().toString();

with something like this

Object selectedItem = getAppComboBox().getSelectedItem();
if (selectedItem == null) return;
String app = selectedItem.toString();

ps: No need to call me "Sir", just James will do!

Thank You Very much James,

Your Idea had been worked perfectly,
You are too genious,

I am very much sorry for the late reply, Just now I had seen your reply and implemented, till now I am out of this work, So I am very much sorry,

Thnak you very much very your help,


"But here there is a small problem now I am getting the data for app combo box based on the selection in the appSet combobox, but not getting the datain the package combo based on the selection in the appSet combo.

Could you please give any idea ,

and I am also not getting any errors now

Thnaks a lot,

Hello Bhargavi
Thanks for the feedback - it's good to know that the suggestion was helpful. That particular problem was a very interesting one, and I really wanted to know if the diagnosis was right.
As for your "small problem now", without all the code (including the database) I can't fix that for you; you will have to debug that yourself. As I understand it the selection from the first list to second is working, and the process for going from the second to the third should be exactly the same process. In that case your problem can't be too hard. If you compare the 1->2 case with the 2->3 case they should match up line for line, with just the variable names being changed in a totally predictable way. My guess is you have either (a) something you fixed in the first case that's not fixed in the second or (b) you have a variable name from the first case that hasn't been replaced correctly for the second case.
If you can't see the problem by inspecting teh code as above, you should use print statements to find exactly where its going wrong.
Good luck
J

Thank You very much James,

Thanks a lot,

Hello James,

If you don't mind can you please explain the code which you had given to me ,
I am also giving the code below

and why do you used Object here

Object selectedItem = getAppComboBox().getSelectedItem();if (selectedItem == null) return;String app = selectedItem.toString();Object selectedItem = getAppComboBox().getSelectedItem();
if (selectedItem == null) return;
String app = selectedItem.toString();

Thank you very much,

Hello James,


Thank you very much,

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.