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.getViewToModel(TableSorter.java:229)
at
com.dss.streamer.client.table.TableSorter.modelIndex(TableSorter.java:241)
at
com.dss.streamer.client.table.TableSorter.getValueAt(TableSorter.java:278)
at javax.swing.JTable.getValueAt(JTable.java:1771)
at javax.swing.JTable.prepareRenderer(JTable.java:3724)
at
javax.swing.plaf.basic.BasicTableUI.paintCell(BasicTableUI.java:1149)
at
javax.swing.plaf.basic.BasicTableUI.paintCells(BasicTableUI.java:1051)
at javax.swing.plaf.basic.BasicTableUI.paint(BasicTableUI.java:974)
at javax.swing.plaf.ComponentUI.update(ComponentUI.java:142)
at javax.swing.JComponent.paintComponent(JComponent.java:541)
at javax.swing.JComponent.paint(JComponent.java:808)
at
javax.swing.JComponent.paintWithOffscreenBuffer(JComponent.java:4787)
at javax.swing.JComponent.paintDoubleBuffered(JComponent.java:4740)
at javax.swing.JComponent._paintImmediately(JComponent.java:4685)
at javax.swing.JComponent.paintImmediately(JComponent.java:4488)
at
javax.swing.RepaintManager.paintDirtyRegions(RepaintManager.java:410)
at
javax.swing.SystemEventQueueUtilities$ComponentWorkRequest.run(SystemEventQueueUtilities.java:117)
at java.awt.event.InvocationEvent.dispatch(InvocationEvent.java:178)
at java.awt.EventQueue.dispatchEvent(EventQueue.java:454)
at
java.awt.EventDispatchThread.pumpOneEventForHierarchy(EventDispatchThread.java:201)
at
java.awt.EventDispatchThread.pumpEventsForHierarchy(EventDispatchThread.java:151)
at
java.awt.EventDispatchThread.pumpEvents(EventDispatchThread.java:145)
at
java.awt.EventDispatchThread.pumpEvents(EventDispatchThread.java:137)
at java.awt.EventDispatchThread.run(EventDispatchThread.java:100)
Thomas Weidenfeller - 23 Jun 2005 08:44 GMT
> 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

Signature
The comp.lang.java.gui FAQ:
ftp://ftp.cs.uu.nl/pub/NEWS.ANSWERS/computer-lang/java/gui/faq
Thomas Weidenfeller - 23 Jun 2005 08:51 GMT
> 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

Signature
The comp.lang.java.gui FAQ:
ftp://ftp.cs.uu.nl/pub/NEWS.ANSWERS/computer-lang/java/gui/faq
farseer - 25 Jun 2005 08:54 GMT
but i have actually put a try/catch block around that to determine that
that is where it is indeed occurring...
Menno Holscher - 25 Jun 2005 14:49 GMT
> 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.

Signature
Groeten van/regards
Menno
farseer - 27 Jun 2005 04:01 GMT
Yes, that is how viewToModel is defined.