Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > Java > TableSorter NPE exception

Reply
Thread Tools

TableSorter NPE exception

 
 
farseer
Guest
Posts: n/a
 
      06-23-2005
Hello,
To implement table sorting in my tables, I am using the following
tableSorter from Sun (note, this is the updated version of tableSorter
that no longer uses a tableMap):
http://java.sun.com/docs/books/tutorial/uiswing/components/table.html#"sorting

However, occassionly, I am receiving the exception below but having
difficulty figuring out why this is happening. The error is shown at
the end of my post and always occurs on the following line:

private Row[] getViewToModel() {
if (viewToModel == null) {
int tableModelRowCount = tableModel.getRowCount();
viewToModel = new Row[tableModelRowCount];
for (int row = 0; row < tableModelRowCount; row++)
{
viewToModel[row] = new Row(row); <--THIS IS THE LINE
CAUSING THE EXCEPTION
}

if (isSorting()) {
Arrays.sort(viewToModel);
}
}
return viewToModel;
}

Why would an NPE be occurring here if we are assigning a value???

Here is the exception stack trace:
java.lang.NullPointerException
at
com.dss.streamer.client.table.TableSorter.getViewT oModel(TableSorter.java:229)
at
com.dss.streamer.client.table.TableSorter.modelInd ex(TableSorter.java:241)
at
com.dss.streamer.client.table.TableSorter.getValue At(TableSorter.java:27
at javax.swing.JTable.getValueAt(JTable.java:1771)
at javax.swing.JTable.prepareRenderer(JTable.java:372 4)
at
javax.swing.plaf.basic.BasicTableUI.paintCell(Basi cTableUI.java:1149)
at
javax.swing.plaf.basic.BasicTableUI.paintCells(Bas icTableUI.java:1051)
at javax.swing.plaf.basic.BasicTableUI.paint(BasicTab leUI.java:974)
at javax.swing.plaf.ComponentUI.update(ComponentUI.ja va:142)
at javax.swing.JComponent.paintComponent(JComponent.j ava:541)
at javax.swing.JComponent.paint(JComponent.java:80
at
javax.swing.JComponent.paintWithOffscreenBuffer(JC omponent.java:4787)
at javax.swing.JComponent.paintDoubleBuffered(JCompon ent.java:4740)
at javax.swing.JComponent._paintImmediately(JComponen t.java:4685)
at javax.swing.JComponent.paintImmediately(JComponent .java:448
at
javax.swing.RepaintManager.paintDirtyRegions(Repai ntManager.java:410)
at
javax.swing.SystemEventQueueUtilities$ComponentWor kRequest.run(SystemEventQueueUtilities.java:117)
at java.awt.event.InvocationEvent.dispatch(Invocation Event.java:17
at java.awt.EventQueue.dispatchEvent(EventQueue.java: 454)
at
java.awt.EventDispatchThread.pumpOneEventForHierar chy(EventDispatchThread.java:201)
at
java.awt.EventDispatchThread.pumpEventsForHierarch y(EventDispatchThread.java:151)
at
java.awt.EventDispatchThread.pumpEvents(EventDispa tchThread.java:145)
at
java.awt.EventDispatchThread.pumpEvents(EventDispa tchThread.java:137)
at java.awt.EventDispatchThread.run(EventDispatchThre ad.java:100)

 
Reply With Quote
 
 
 
 
Thomas Weidenfeller
Guest
Posts: n/a
 
      06-23-2005
farseer wrote:
> Why would an NPE be occurring here if we are assigning a value???


My random guess would be that you are not looking at the source code
from which your class was compiled.

Clean your build environment, compile and install everything from scratch.

/Thomas


--
The comp.lang.java.gui FAQ:
ftp://ftp.cs.uu.nl/pub/NEWS.ANSWERS/...g/java/gui/faq
 
Reply With Quote
 
 
 
 
Thomas Weidenfeller
Guest
Posts: n/a
 
      06-23-2005
Thomas Weidenfeller wrote:
> Clean your build environment, compile and install everything from scratch.


To avoid any misunderstandings: Only compile and install your
application from scratch, not the JDK, IDE, etc.

/Thomas

--
The comp.lang.java.gui FAQ:
ftp://ftp.cs.uu.nl/pub/NEWS.ANSWERS/...g/java/gui/faq
 
Reply With Quote
 
farseer
Guest
Posts: n/a
 
      06-25-2005
but i have actually put a try/catch block around that to determine that
that is where it is indeed occurring...

 
Reply With Quote
 
Menno Holscher
Guest
Posts: n/a
 
      06-25-2005
farseer wrote:

> but i have actually put a try/catch block around that to determine that
> that is where it is indeed occurring...


Is your definition of viewToModel:
Row[] viewToModel ;
Otherwise you will get a NPE as you stated. Also a superclass of Row may be
acceptable.
--
Groeten van/regards

Menno
 
Reply With Quote
 
farseer
Guest
Posts: n/a
 
      06-27-2005
Yes, that is how viewToModel is defined.

 
Reply With Quote
 
arkoenne arkoenne is offline
Junior Member
Join Date: Oct 2006
Posts: 1
 
      10-27-2006
Hello,

I have the same NullPointerException problem with the TableSorter class. The row class constructor and the Row[] variable definition are okay. When I debug the code, it looks like the viewToModel variable can happen to be != null int the for constructor for row count 1 to 200, but at row count 201 it is suddenly null.

Any further ideas or suggestions?

Thanks
arkoenne
 
Reply With Quote
 
suvacodecobra suvacodecobra is offline
Junior Member
Join Date: Nov 2006
Location: Brazil
Posts: 1
 
      11-16-2006
To not receive more the NPE in the TableModelSorter follow the steps:

1-)Create an backupToModel array:

private Row[] viewToModel;
private Row[] backupToModel; // <- Add this line

2-)Change the method getViewToModel():

private Row[] getViewToModel() { // <- Change this method
if (viewToModel == null) {
int tableModelRowCount = tableModel.getRowCount();
backupToModel = new Row[tableModelRowCount];
viewToModel = new Row[1];
for (int row = 0; row < tableModelRowCount; row++) {
backupToModel[row] = new Row(row);
}

if (isSorting()) {
Arrays.sort(backupToModel);
}
}
return backupToModel;
}

Thatīs it... If you have more questions or doubts just send me a message...

Posted in http://forum.java.sun.com/thread.jspa?messageID=4469989 too..
 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
TableSorter.java v2.1 ouroborus Java 8 05-01-2006 09:17 PM
Eventhandling with TableSorter and TableFilterer cm Java 2 08-09-2004 09:36 AM
Sun's swing TableSorter VisionSet Java 8 06-07-2004 04:12 AM
JTable and TableSorter Ques Tim Java 1 05-19-2004 08:23 AM
Difficulties using TableSorter class from Sun's tutorial. Robert Java 3 10-06-2003 01:36 AM



Advertisments
 



1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57