Null pointer exception in a swing component

Stack trace:

Exception in thread "AWT-EventQueue-0" java.lang.NullPointerException
        at javax.swing.plaf.basic.BasicTableUI.paintCell(BasicTableUI.java:2073
        at javax.swing.plaf.basic.BasicTableUI.paintCells(BasicTableUI.java:197
        at javax.swing.plaf.basic.BasicTableUI.paint(BasicTableUI.java:1770)
...

In my case, this happened because I was updating this swing component from a separated thread. A way to avoid this is to wait to all pending AWT events to be processed. This can be done with SwingUtilities.invokeLater.

SwingUtilities.invokeLater(new Runnable(){
    void doRun(){
        // code that updates the component
    } 
});
Advertisements

Leave a Reply

Please log in using one of these methods to post your comment:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s