Results 1 to 3 of 3
- 03-31-2012, 04:48 PM #1
Member
- Join Date
- Mar 2012
- Location
- England
- Posts
- 13
- Rep Power
- 0
ComboBox - Adding Items Creating NPE
I am trying to populate a JComboBox in a GUI (using swing). When I execute this, for some reason I keep getting a Null Point Exception error and I cannot figure out why. Specifically because in another application the exact same commands work just fine.
The commands I am using are:
Organization is an enum that is available to the class that contains this method.Java Code:/** * Method to populate the list of organisations able to be selected. */ private void populateOrgSelection() { ArrayList<Organization> listOfOrgs = new ArrayList<Organization>( this.getListofOrganizations()); try { this.orgSelectionComboBox.addItem(""); // LINE 141 for (Organization eachOrg : listOfOrgs) { this.orgSelectionComboBox.addItem(eachOrg); } } catch (NullPointerException npe) { System.out.println("There was a Null Error while populating " + "the org list. " + npe.getMessage()); npe.printStackTrace(); } }
If I delete this.orgSelectionComboBox.addItem("") I still get an NPE but on the forEach addItem() command line instead.
I put a System.out.println(eachOrg) statement in the forEach statement I get a printed listed of each of the Organizations. So the ArrayList collection I am using is not null.
The stack trace for this is:
There was a Null Error while populating the org list. null
java.lang.NullPointerException
at guis.NewPersonGUI.populateOrgSelection(NewPersonGU I.java:141)
at guis.NewPersonGUI.<init>(NewPersonGUI.java:55)
at guis.RecruitmentGUI.addNewButtonActionPerformed(Re cruitmentGUI.java:1108)
at guis.RecruitmentGUI.access$900(RecruitmentGUI.java :31)
at guis.RecruitmentGUI$9.actionPerformed(RecruitmentG UI.java:509)
at javax.swing.AbstractButton.fireActionPerformed(Abs tractButton.java:1995)
at javax.swing.AbstractButton$Handler.actionPerformed (AbstractButton.java:2318)
at javax.swing.DefaultButtonModel.fireActionPerformed (DefaultButtonModel.java:387)
at javax.swing.DefaultButtonModel.setPressed(DefaultB uttonModel.java:242)
at javax.swing.plaf.basic.BasicButtonListener.mouseRe leased(BasicButtonListener.java:236)
at java.awt.Component.processMouseEvent(Component.jav a:6267)
at javax.swing.JComponent.processMouseEvent(JComponen t.java:3267)
at java.awt.Component.processEvent(Component.java:603 2)
at java.awt.Container.processEvent(Container.java:204 1)
at java.awt.Component.dispatchEventImpl(Component.jav a:4630)
at java.awt.Container.dispatchEventImpl(Container.jav a:2099)
at java.awt.Component.dispatchEvent(Component.java:44 60)
at java.awt.LightweightDispatcher.retargetMouseEvent( Container.java:4577)
at java.awt.LightweightDispatcher.processMouseEvent(C ontainer.java:4238)
at java.awt.LightweightDispatcher.dispatchEvent(Conta iner.java:4168)
at java.awt.Container.dispatchEventImpl(Container.jav a:2085)
at java.awt.Window.dispatchEventImpl(Window.java:2478 )
at java.awt.Component.dispatchEvent(Component.java:44 60)
I am totally stymied as to why I am getting this error - Any ideas from anyone?
- 03-31-2012, 05:15 PM #2
Re: ComboBox - Adding Items Creating NPE
Did you initialize orgSelectionComboBox?
To get better help sooner, post a SSCCE (Short, Self Contained, Compilable and Executable) example that demonstrates the problem.
dbWhy do they call it rush hour when nothing moves? - Robin Williams
- 03-31-2012, 05:31 PM #3
Member
- Join Date
- Mar 2012
- Location
- England
- Posts
- 13
- Rep Power
- 0
Similar Threads
-
SWT Combobox: items not showing up until you hover over them
By mlpehlivan in forum SWT / JFaceReplies: 1Last Post: 02-03-2012, 12:49 PM -
Adding items from one ArryList to another
By Java-Guy in forum New To JavaReplies: 4Last Post: 01-17-2011, 04:19 AM -
Adding \ removing items from Jlist
By Desperado in forum AWT / SwingReplies: 10Last Post: 12-17-2009, 12:48 PM -
[SOLVED] Adding ComboBox
By impact in forum New To JavaReplies: 2Last Post: 05-02-2008, 08:43 PM -
Adding items to a jComboBox
By tronovan in forum New To JavaReplies: 0Last Post: 08-08-2007, 08:48 AM


LinkBack URL
About LinkBacks
Reply With Quote
Bookmarks