Re: Errors when deleting a row in a JTable.

From: Soren Kuula (dongfangREMOVE_at_bitplanet.net)
Date: 05/01/04


Date: Sat, 01 May 2004 15:25:19 +0200

Bernard Koninckx wrote:
> The code below return a good class object but I've already the same stack
> trace
> error
>
> public Class getColumnClass(int columnIndex) {
> Column colInfo = (Column)columns.get(columnIndex);
> String colName = colInfo.getColumnName();
> Field fieldInfo = findField(dataObjectClass, colName);
> Class className = fieldInfo.getType();
>
> return fieldInfo.getType();
> }
>
> I don't understand what's really the problem.

The problem IS your column classes. I can see that you sometimes return
Integer.TYPE, or TYPE of the wrapper class for some other simple type.
It does not work - JTable has no renderer installes for these types (I
am not even sure they are subtypes of Object). That's what you get
nullpointer exc.

Try this:
    public Class getColumnClass(int columnIndex) {
             Column colInfo = (Column)columns.get(columnIndex);
             String colName = colInfo.getColumnName();
             Field fieldInfo = findField(dataObjectClass, colName);
             Class className = fieldInfo.getType();
             if (className == Integer.TYPE)
             return Object.class;
             return fieldInfo.getType();
// if (getRowCount()>=1)
// return getValueAt(0,columnIndex).getClass();
// return null;
     }

and it quits crashing.

That said, I think there is something overly complicated about your
table model. I't not worth all of your effort (reflection) to avoid
wrapper types in a TableModel, if that's what you want to do. If you
want to, a better way is still to have the getValueAt return a wrapper
type for underlying primitive types.

Also, avoid file name literals in your code. The code would not run here
until I had found and corrected them. And get rid o' them Vectors :)

Soren



Relevant Pages

  • Re: Multiple Exception Definitions in One File
    ... > public class ExcepOne extends Exception ... > UseExceps.java:10: an enclosing instance that contains Exceps.ExcepOne ... Non-static inner class objects have a reference to their enclosing outer ... Static inner class object don't have a reference to an enclosing outer class ...
    (comp.lang.java.programmer)
  • Re: Sorting a System.Collections.ObjectModel.Collection
    ... |> Public Class CollectionBase ... |> Listhas a Sort method. ... |> Public Class PersonCollection ...
    (microsoft.public.dotnet.languages.vb)
  • Re: Marshaling Delegates as Struct/Class Members
    ... >I understand delegates do not need to be pinned, but its the class object ... > public class TestObject ... > value, GCHandleType type) ... > Is there an easy way to marshal delegates as part of a struct? ...
    (microsoft.public.dotnet.languages.csharp)
  • Re: Marshaling Delegates as Struct/Class Members
    ... >>I understand delegates do not need to be pinned, but its the class object ... >> public class TestObject ... >> value, GCHandleType type) ... >> Is there an easy way to marshal delegates as part of a struct? ...
    (microsoft.public.dotnet.languages.csharp)
  • Re: Sorting a System.Collections.ObjectModel.Collection
    ... Remember that Collectionis simply a wrapper for an object that ... Listhas a Sort method. ... Public Class PersonCollection ... Public Sub Sort() ...
    (microsoft.public.dotnet.languages.vb)