Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
HomeAnnouncementsWhite Papers
Discussion GroupsFirst AidDatabasesJavaBeansGUIJava 3DVirtual MachineCORBASecurityToolsGeneral
Java DirectoryOpen Source ProjectsSample Book ChaptersUser GroupsWeb Resources
Related Topics
Databases.NETMore Topics ...

Java Forum / General / December 2007

Tip: Looking for answers? Try searching our database.

Problem when removing data out of a combo box

Thread view: 
christopher_board@yahoo.co.uk - 17 Dec 2007 08:39 GMT
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
Sabine Dinis Blochberger - 17 Dec 2007 09:41 GMT
>     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();
>
[quoted text clipped - 13 lines]
> 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) ;)

> Thank you

Signature

Sabine Dinis Blochberger

Op3racional
www.op3racional.eu

christopher_board@yahoo.co.uk - 17 Dec 2007 10:16 GMT
On 17 Dec, 09:41, Sabine Dinis Blochberger <no.s...@here.invalid>
wrote:
> christopher_bo...@yahoo.co.uk wrote:
> >     public void jMenuOptionsLocateDataFile_actionPerformed(ActionEvent
[quoted text clipped - 44 lines]
>
> - 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


Free Magazines

Get these publications absolutely FREE for up to 12 months. There are no hidden fees and no obligation. Simply choose a title, complete the application form and submit it. Read more ...

Oracle MagazineNetwork ComputingComputer WorldBio-IT WorldeWeekInformation WeekInfosecurity
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2008 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.