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 / GUI / November 2004

Tip: Looking for answers? Try searching our database.

JTable bug

Thread view: 
AntiQual - 11 Nov 2004 19:29 GMT
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 ?

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)
    at javax.swing.plaf.basic.BasicTableUI.paint(BasicTableUI.java:1470)
    at javax.swing.plaf.ComponentUI.update(ComponentUI.java:142)
    at javax.swing.JComponent.paintComponent(JComponent.java:740)
    at javax.swing.JComponent.paint(JComponent.java:1003)
    at javax.swing.JComponent.paintWithOffscreenBuffer(JComponent.java:4930)
    at javax.swing.JComponent.paintDoubleBuffered(JComponent.java:4883)
    at javax.swing.JComponent._paintImmediately(JComponent.java:4826)
    at javax.swing.JComponent.paintImmediately(JComponent.java:4633)
    at javax.swing.RepaintManager.paintDirtyRegions(RepaintManager.java:451)
    at javax.swing.SystemEventQueueUtilities$ComponentWorkRequest.run(SystemEventQueueUtilities.java:114)
    at java.awt.event.InvocationEvent.dispatch(InvocationEvent.java:209)
    at java.awt.EventQueue.dispatchEvent(EventQueue.java:461)
    at java.awt.EventDispatchThread.pumpOneEventForHierarchy(EventDispatchThread.java:234)
    at java.awt.EventDispatchThread.pumpEventsForHierarchy(EventDispatchThread.java:163)
    at java.awt.EventDispatchThread.pumpEvents(EventDispatchThread.java:157)
    at java.awt.EventDispatchThread.pumpEvents(EventDispatchThread.java:149)
    at java.awt.EventDispatchThread.run(EventDispatchThread.java:110)
Andrew Thompson - 11 Nov 2004 19:42 GMT
> 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?

Signature

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 - 11 Nov 2004 19:44 GMT
(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.."
..
AntiQual - 12 Nov 2004 10:49 GMT
> > AWT-EventQueue-0
>
[quoted text clipped - 5 lines]
>
> 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 - 12 Nov 2004 09:13 GMT
> Hello everybody
>
[quoted text clipped - 3 lines]
> 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).

Signature

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

Babu Kalakrishnan - 12 Nov 2004 11:09 GMT
> I have a nasty problem with a jtable
>
[quoted text clipped - 9 lines]
>     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
Nigel Wade - 16 Nov 2004 09:38 GMT
> 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.

Signature

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

Babu Kalakrishnan - 16 Nov 2004 13:15 GMT
>>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
[quoted text clipped - 6 lines]
> 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 - 16 Nov 2004 16:56 GMT
>>>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
[quoted text clipped - 9 lines]
> 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...

Signature

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



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.