Problem when removing data out of a combo box

C

christopher_board

Hi all,

I am currently developing a java application that has a combo box and
a list box. I have a menu options which is called Locate Data File.
When I click on this menu item it is supposed to clear the data from
the list box and from the combo box and then load a dialogue box.

However what it is doing is, when I click the menu the program crashes
and comes up with an error saying:
Exception in thread "AWT-EventQueue-0"
java.lang.NullPointerException.
However the combo box and the JList clears the data out if it. When i
then click the menu again the program works without coming up with the
error.

When I have debugged the program it is falling over around the part
where it is clearing the combo box. Below is the code that I am using:

public void jMenuOptionsLocateDataFile_actionPerformed(ActionEvent
e) {
cboRoomNumber.removeAllItems();
lstComputerNames.getModel();
data.removeAllElements();
lstComputerNames.removeAll();


DataFile dlg = new DataFile(this);
Dimension dlgSize = dlg.getPreferredSize();
Dimension frmSize = getSize();
Point loc = getLocation();
dlg.setLocation((frmSize.width - dlgSize.width) / 2 + loc.x,
(frmSize.height - dlgSize.height) / 2 +
loc.y);
dlg.setModal(true);
dlg.pack();
dlg.setVisible(true);
}

Where it says cboRoomNumber.removeAllItems(); this is where it is
supposed to clear the combo box but it seems to be falling over at
this point.

Any help in this matter would be highly appreciated.

Thank you
 
S

Sabine Dinis Blochberger

public void jMenuOptionsLocateDataFile_actionPerformed(ActionEvent
e) {
cboRoomNumber.removeAllItems();
lstComputerNames.getModel();

You don't hold on to the model here.
data.removeAllElements();

data seems to not have been initialized (nor declared in your example).
lstComputerNames.removeAll();


DataFile dlg = new DataFile(this);
Dimension dlgSize = dlg.getPreferredSize();
Dimension frmSize = getSize();
Point loc = getLocation();
dlg.setLocation((frmSize.width - dlgSize.width) / 2 + loc.x,
(frmSize.height - dlgSize.height) / 2 +
loc.y);
dlg.setModal(true);
dlg.pack();
dlg.setVisible(true);
}

Where it says cboRoomNumber.removeAllItems(); this is where it is
supposed to clear the combo box but it seems to be falling over at
this point.

Do set a breakpoint there to make sure this is the offending line. I
suspect it is actually the data.removeAllElements().
Any help in this matter would be highly appreciated.

It would be more helpful (and others will point out the same), to post a
self contained short/simple compilable (!) code example. One that can be
copied into a file and compiled with no further action. Also called
SCCEE (IIRC) ;)
 
C

christopher_board

You don't hold on to the model here.


data seems to not have been initialized (nor declared in your example).








Do set a breakpoint there to make sure this is the offending line. I
suspect it is actually the data.removeAllElements().




It would be more helpful (and others will point out the same), to post a
self contained short/simple compilable (!) code example. One that can be
copied into a file and compiled with no further action. Also called
SCCEE (IIRC) ;)




--
Sabine Dinis Blochberger

Op3racionalwww.op3racional.eu- Hide quoted text -

- Show quoted text -

Thanks for your. I have managed to resolve the problem before I saw
your message. What I believe I was doing was clearing the data out of
combo box instead of removing the data out of the vector that is being
used. I got the model and then and removed all the elements from the
vector and the problem no longer occurs.

Thanks for your help
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,744
Messages
2,569,484
Members
44,903
Latest member
orderPeak8CBDGummies

Latest Threads

Top