Errors when deleting a row in a JTable.

From: Bernard Koninckx (koninckxbernard_at_excite.com)
Date: 04/30/04


Date: Fri, 30 Apr 2004 16:51:23 +0200

Hi everybody,

The following code (putted in a inherited object from AbstractTableModel
object) make some errors :

public void deleteRow(int rowToDelete){
     try{
      Object dataObject = datas.get(rowToDelete);
      String idName = idField.getColumnName();
            Method method = dataObjectClass.getMethod("get" +
StringServices.capitalize(idName), null);
            Object o = method.invoke(dataObject, null);
      deletedRows.add(o);
      datas.remove(rowToDelete);
      fireTableRowsDeleted(rowToDelete, rowToDelete);
     }
     catch(Exception e){
      e.printStackTrace();
     }
    }

I don't understand why.

And here is the Stack trace exception

java.lang.NullPointerException
 at javax.swing.JTable.prepareRenderer(Unknown Source)
 at javax.swing.plaf.basic.BasicTableUI.paintCell(Unknown Source)
 at javax.swing.plaf.basic.BasicTableUI.paintCells(Unknown Source)
 at javax.swing.plaf.basic.BasicTableUI.paint(Unknown Source)
 at javax.swing.plaf.ComponentUI.update(Unknown Source)
 at javax.swing.JComponent.paintComponent(Unknown Source)
 at javax.swing.JComponent.paint(Unknown Source)
 at javax.swing.JComponent.paintChildren(Unknown Source)
 at javax.swing.JComponent.paint(Unknown Source)
 at javax.swing.JViewport.paint(Unknown Source)
 at javax.swing.JComponent.paintChildren(Unknown Source)
 at javax.swing.JComponent.paint(Unknown Source)
 at javax.swing.JComponent.paintChildren(Unknown Source)
 at javax.swing.JComponent.paint(Unknown Source)
 at javax.swing.JComponent.paintChildren(Unknown Source)
 at javax.swing.JComponent.paint(Unknown Source)
 at javax.swing.JLayeredPane.paint(Unknown Source)
 at javax.swing.JComponent.paintChildren(Unknown Source)
 at javax.swing.JComponent.paintWithOffscreenBuffer(Unknown Source)
 at javax.swing.JComponent.paintDoubleBuffered(Unknown Source)
 at javax.swing.JComponent.paint(Unknown Source)
 at java.awt.GraphicsCallback$PaintCallback.run(Unknown Source)
 at sun.awt.SunGraphicsCallback.runOneComponent(Unknown Source)
 at sun.awt.SunGraphicsCallback.runComponents(Unknown Source)
 at java.awt.Container.paint(Unknown Source)
 at sun.awt.RepaintArea.paint(Unknown Source)
 at sun.awt.windows.WComponentPeer.handleEvent(Unknown Source)
 at java.awt.Component.dispatchEventImpl(Unknown Source)
 at java.awt.Container.dispatchEventImpl(Unknown Source)
 at java.awt.Window.dispatchEventImpl(Unknown Source)
 at java.awt.Component.dispatchEvent(Unknown Source)
 at java.awt.EventQueue.dispatchEvent(Unknown Source)
 at java.awt.EventDispatchThread.pumpOneEventForHierarchy(Unknown Source)
 at java.awt.EventDispatchThread.pumpEventsForHierarchy(Unknown Source)
 at java.awt.EventDispatchThread.pumpEvents(Unknown Source)
 at java.awt.EventDispatchThread.pumpEvents(Unknown Source)
 at java.awt.EventDispatchThread.run(Unknown Source)

Thanks all

Bernard