F
farseer
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)
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)