Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

Re: JTable bug

0 views
Skip to first unread message

Andrew Thompson

unread,
Nov 11, 2004, 2:42:14 PM11/11/04
to
On 11 Nov 2004 11:29:05 -0800, AntiQual wrote:

> AWT-EventQueue-0

A quick search of that on Sun's bug parade led me to..
<http://bugs.sun.com/bugdatabase/view_bug.do?bug_id=4819544>
Which links to two other bugs (one of which mentions
the string), it points to the problem being
"..checking for null values before trying to format them.."

Could that be the case with your code?

--
Andrew Thompson
http://www.PhySci.org/codes/ Web & IT Help
http://www.PhySci.org/ Open-source software suite
http://www.1point1C.org/ Science & Technology
http://www.LensEscapes.com/ Images that escape the mundane

Andrew Thompson

unread,
Nov 11, 2004, 2:44:28 PM11/11/04
to
On Thu, 11 Nov 2004 19:42:14 GMT, Andrew Thompson wrote:

(snip)


> Which links to two other bugs (one of which mentions

> the string), it points to the problem ..

(slaps forehead) *solution*

>..being


> "..checking for null values before trying to format them.."

..

Nigel Wade

unread,
Nov 12, 2004, 4:13:53 AM11/12/04
to
AntiQual wrote:

> Hello everybody
>
> I have a nasty problem with a jtable
>
> An exception is thrown at some point when the table is drawn but as
> can be seen below the stacktrace is completely in "sun code", any
> ideas what would cause something like this to happen ?

Failing to follow the API.
Feeding garbage to the JTable - garbage in/garbage out.

>
> I would post some of my own code but it doesn't seem to be involved so

Yeah, right...

> I don't know what part of the code to post. Any response would be
> greatly appreciated.
>

The most likely reason is that model you have asked the table to render
contains a null (been there, done that - didn't bother with the T-shirt).

--
Nigel Wade, System Administrator, Space Plasma Physics Group,
University of Leicester, Leicester, LE1 7RH, UK
E-mail : n...@ion.le.ac.uk
Phone : +44 (0)116 2523548, Fax : +44 (0)116 2523555

Babu Kalakrishnan

unread,
Nov 12, 2004, 6:09:46 AM11/12/04
to
AntiQual wrote:

> I have a nasty problem with a jtable
>
> An exception is thrown at some point when the table is drawn but as
> can be seen below the stacktrace is completely in "sun code", any
> ideas what would cause something like this to happen ?
>

> I would post some of my own code but it doesn't seem to be involved so

> I don't know what part of the code to post. Any response would be
> greatly appreciated.
>

> Exception in thread "AWT-EventQueue-0" java.lang.NullPointerException
> at javax.swing.plaf.basic.BasicTableUI.paintCell(BasicTableUI.java:1646)
> at javax.swing.plaf.basic.BasicTableUI.paintCells(BasicTableUI.java:1547)

As opposed to the views of some other posters, I think JTable (or at
least the JDK 1.4 implementation of it) does allow nulls as values for
cells - The default cell renderers display these as blank cells.

Generally the UI code has nothing to do with the actual rendering of the
cell as such - this is the task of the renderer. So if the cause for
this exception was really a cell value being null, I would expect the
exception to be thrown from the CellRenderer class rather than the UI
class.

The most common cause I have seen for exceptions such as this is not
folowing thread safety. I'd advice you to check if some code in your
program is trying to modify the table (or its model) from a thread other
than the EDT.

BK

AntiQual

unread,
Nov 12, 2004, 5:49:49 AM11/12/04
to
Andrew Thompson <SeeMy...@www.invalid> wrote in message news:<15wrzh0r8y1wz.o47kesixwj22$.d...@40tude.net>...

> On 11 Nov 2004 11:29:05 -0800, AntiQual wrote:
>
> > AWT-EventQueue-0
>
> A quick search of that on Sun's bug parade led me to..
> <http://bugs.sun.com/bugdatabase/view_bug.do?bug_id=4819544>
> Which links to two other bugs (one of which mentions
> the string), it points to the problem being
> "..checking for null values before trying to format them.."
>
> Could that be the case with your code?

Thx for the reply (I am not sure I undestand your other post so I'm
replying to this one :))

The bugs you refer to seem to be related to getColumnClass while this
one is paintCell but they do seem to be related in both cases there
is not check for null values - it appears that sun doesn't seem to
think that is nessesary :).

This is the part of the sun code that throws the exception:

private void paintCell(Graphics g, Rectangle cellRect, int row, int
column) {
if (table.isEditing() && table.getEditingRow()==row &&
table.getEditingColumn()==column) {
Component component = table.getEditorComponent();
component.setBounds(cellRect);
component.validate();
}
else {
TableCellRenderer renderer = table.getCellRenderer(row,
column);
Component component = table.prepareRenderer(renderer, row,
column);
rendererPane.paintComponent(g, component, table,
cellRect.x, cellRect.y,
cellRect.width,
cellRect.height, true);
}
}

It seems to be the "renderePane.paintComponent( ..." that throws the
exception probably because rendererPane or maybe cellRect is null.
Again this method is not written or even called by me which makes it
rather difficult to find out what I am doing wrong :(.

Nigel Wade

unread,
Nov 16, 2004, 4:38:48 AM11/16/04
to
Babu Kalakrishnan wrote:

>
> As opposed to the views of some other posters, I think JTable (or at
> least the JDK 1.4 implementation of it) does allow nulls as values for
> cells - The default cell renderers display these as blank cells.
>

Are you sure about that?

The emperical evidence I have gained would suggest otherwise (at least in
1.4.2). When I inadvertently stored some null entries in a table model the
result was NullPointerExceptions when the table attempted to render a null
entry.

Babu Kalakrishnan

unread,
Nov 16, 2004, 8:15:59 AM11/16/04
to
Nigel Wade wrote:
> Babu Kalakrishnan wrote:
>
>
>>As opposed to the views of some other posters, I think JTable (or at
>>least the JDK 1.4 implementation of it) does allow nulls as values for
>>cells - The default cell renderers display these as blank cells.
>>
>
>
> Are you sure about that?
>
> The emperical evidence I have gained would suggest otherwise (at least in
> 1.4.2). When I inadvertently stored some null entries in a table model the
> result was NullPointerExceptions when the table attempted to render a null
> entry.
>

Try running the following program and check if it gives any
NullPointerExceptions. On my system it doesn't (JDK 1.4.2 Linux)

import java.awt.BorderLayout;
import javax.swing.JFrame;
import javax.swing.JScrollPane;
import javax.swing.JTable;
import javax.swing.table.AbstractTableModel;

public class TableNullTest
{

public static class NullTestModel extends AbstractTableModel
{

public int getColumnCount()
{
return 6;
}

public String getColumnName(int columnIndex)
{
if ((columnIndex & 1) != 0) return "Null";
else return "Col." + columnIndex ;
}

public int getRowCount()
{
return 5;
}

public Object getValueAt(int rowIndex, int columnIndex)
{
if ((columnIndex & 1) != 0)
return null;
else return "Cell "+rowIndex+","+columnIndex;
}
}

public static void main(String[] args)
{
JFrame fr = new JFrame();
fr.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
JTable table = new JTable(new NullTestModel());
JScrollPane pane = new JScrollPane(table);
fr.getContentPane().add(pane,BorderLayout.CENTER);
fr.pack();
fr.show();
}
}

Nigel Wade

unread,
Nov 16, 2004, 11:56:27 AM11/16/04
to
Babu Kalakrishnan wrote:

> Nigel Wade wrote:
>> Babu Kalakrishnan wrote:
>>
>>
>>>As opposed to the views of some other posters, I think JTable (or at
>>>least the JDK 1.4 implementation of it) does allow nulls as values for
>>>cells - The default cell renderers display these as blank cells.
>>>
>>
>>
>> Are you sure about that?
>>
>> The emperical evidence I have gained would suggest otherwise (at least in
>> 1.4.2). When I inadvertently stored some null entries in a table model
the
>> result was NullPointerExceptions when the table attempted to render a
null
>> entry.
>>
>
> Try running the following program and check if it gives any
> NullPointerExceptions. On my system it doesn't (JDK 1.4.2 Linux)

Hmm, it works on my system as well.

My memory must be faulty. I definitely remember getting
NullPointerExceptions when I had nulls in the model, but it's while ago and
I don't remember the exact details. It could be I was using a custom model
and hadn't programmed it to handle null fields correctly...

0 new messages