Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
HomeAnnouncementsWhite Papers
Discussion GroupsFirst AidDatabasesJavaBeansGUIJava 3DVirtual MachineCORBASecurityToolsGeneral
Java DirectoryOpen Source ProjectsSample Book ChaptersUser GroupsWeb Resources
Related Topics
Databases.NETMore Topics ...

Java Forum / General / June 2005

Tip: Looking for answers? Try searching our database.

TableSorter NPE exception

Thread view: 
farseer - 23 Jun 2005 04:48 GMT
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.


Free Magazines

Get these publications absolutely FREE for up to 12 months. There are no hidden fees and no obligation. Simply choose a title, complete the application form and submit it. Read more ...

Oracle MagazineNetwork ComputingComputer WorldBio-IT WorldeWeekInformation WeekInfosecurity
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2008 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.