🚀 go-pugleaf

RetroBBS NetNews Server

Inspired by RockSolid Light RIP Retro Guy

Thread View: borland.public.jbuilder.java.swing
2 messages
2 total messages Started by Glen Hanket Sat, 17 Jul 2004 00:04
previously debugged code not working in JBX - ListSelectionListener
#810
Author: Glen Hanket
Date: Sat, 17 Jul 2004 00:04
62 lines
3639 bytes
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
	at dialogs.DialogExpense.moveLineData(DialogExpense.java:217)
	at dialogs.SplitsDialog.editLine(SplitsDialog.java:99)
	at dialogs.SummaryPane.valueChanged(SummaryPane.java:56)
	at javax.swing.JList.fireSelectionValueChanged(JList.java:1321)
	at javax.swing.JList$ListSelectionHandler.valueChanged(JList.java:1335)
	at 
javax.swing.DefaultListSelectionModel.fireValueChanged(DefaultListSelectionModel.java:187)
	at 
javax.swing.DefaultListSelectionModel.fireValueChanged(DefaultListSelectionModel.java:167)
	at 
javax.swing.DefaultListSelectionModel.fireValueChanged(DefaultListSelectionModel.java:214)
	at 
javax.swing.DefaultListSelectionModel.removeIndexInterval(DefaultListSelectionModel.java:546)
	at 
javax.swing.plaf.basic.BasicListUI$ListDataHandler.intervalRemoved(BasicListUI.java:1561)
	at 
javax.swing.AbstractListModel.fireIntervalRemoved(AbstractListModel.java:160)
	at javax.swing.DefaultListModel.removeElement(DefaultListModel.java:364)
	at dialogs.SummaryPane.remove(SummaryPane.java:65)
	at dialogs.SplitsDialog.editLine(SplitsDialog.java:97)
	at dialogs.SummaryPane.valueChanged(SummaryPane.java:56) *** first 
entry to my program
	at javax.swing.JList.fireSelectionValueChanged(JList.java:1321)
	at javax.swing.JList$ListSelectionHandler.valueChanged(JList.java:1335)
	at 
javax.swing.DefaultListSelectionModel.fireValueChanged(DefaultListSelectionModel.java:187)
	at 
javax.swing.DefaultListSelectionModel.fireValueChanged(DefaultListSelectionModel.java:157)

Thus, after it enters my code with a non-null line, it eventually enters 
DefaultListModel.removeElement - and next thing I know I'm getting 
called at the same entry point with a null entry.

I'm stumped (and when I tried to open JBuilderX help, it can't find ANY 
help files whatsoever, so I can't look to see if the class has changed.

Can anyone help me out?

Thanks in advance!

Glen Hanket
Re: previously debugged code not working in JBX - ListSelectionListener
#812
Author: Paul Nichols (TeamB)
Date: Sat, 17 Jul 2004 04:38
35 lines
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.
 
Thread Navigation

This is a paginated view of messages in the thread with full content displayed inline.

Messages are displayed in chronological order, with the original post highlighted in green.

Use pagination controls to navigate through all messages in large threads.

Back to All Threads