Article View: borland.public.jbuilder.java.swing
Article #812Re: previously debugged code not working in JBX - ListSelectionListener
From: Paul Nichols (TeamB)
Date: Sat, 17 Jul 2004 04:38
Date: Sat, 17 Jul 2004 04:38
35 lines
2394 bytes
2394 bytes
Glen Hanket wrote:
> Help!
>
> I recently bought a new PC, and decided to upgrade from JBuilder5. The
> code I developed in JB5 now has a bug in it, in a class that implements
> ListSelectionListener and contains a DefaultListModel. The code waits
> for a click on an entry in the list, and then should delete it from the
> list so I can display it for editing elsewhere in the dialog box.
>
> My code inside SummaryPane (which implements the listener):
>
> *51* public void valueChanged(ListSelectionEvent evt) {
> *52* if ( !evt.getValueIsAdjusting() )
> *53* {
> *54* JList source = (JList)evt.getSource();
> *55* BHXLines line = (BHXLines)source.getSelectedValue();
> *56* parent.editLine(line);
> *57* }
> *58* }
>
> The resulting null-pointer exception:
> java.lang.NullPointerException
I do not know what parent.editLine(line) does, but if it deletes the item,
and you do not refresh the List, the problem is that the index has changed
at the position you selected. If the index is say 5, in a 0 to 5 item based
List, and you delete Item 5, then you now actually have a 0-4 indexed list.
If the user tries to delete Item 5 from the list next time, then there is no
5th index in the list. Therefore, a null pointer exception or List index
out of bounds will be thrown.
I do not know if this is your problem, but you might want to check this.
Technical Details
Message-ID:
<40f8a87f@newsgroups.borland.com>Path:
arc1-ca.pugleaf.net!g2news1.google.com!news2.google.com!proxad.net!news.tele.dk!news.tele.dk!small.news.tele.dk!irazu.switch.ch!switch.ch!news.belwue.de!newsfeed01.sul.t-online.de!t-online.de!newsgroups.borland.com!not-for-mailReferences:
<40f86d1a@newsgroups.borland.com>Show Full Headers
Complete Article Headers
X-Google-Thread: 111d45,6198df393cba180c X-Google-Attributes: gid111d45,public X-Google-Language: ENGLISH,ASCII-7-bit Message-ID: <40f8a87f@newsgroups.borland.com> From: "Paul Nichols (TeamB)" <paul@comp.net> Subject: Re: previously debugged code not working in JBX - ListSelectionListener Newsgroups: borland.public.jbuilder.java.swing Reply-To: paul@comp.net Mail-Copies-To: paul@comp.net Date: Sat, 17 Jul 2004 00:38:20 -0400 References: <40f86d1a@newsgroups.borland.com> Lines: 36 Organization: clc User-Agent: KNode/0.7.6 MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Transfer-Encoding: 7Bit NNTP-Posting-Host: 68.71.188.114 X-Trace: newsgroups.borland.com 1090037888 68.71.188.114 (16 Jul 2004 21:18:08 -0700) Path: arc1-ca.pugleaf.net!g2news1.google.com!news2.google.com!proxad.net!news.tele.dk!news.tele.dk!small.news.tele.dk!irazu.switch.ch!switch.ch!news.belwue.de!newsfeed01.sul.t-online.de!t-online.de!newsgroups.borland.com!not-for-mail