views:

384

answers:

2

I keep getting this NPE in my application and I can't seem to get rid of it because it is not showing up in any of my source code. As you can see from the stacktrace it is not happening in my code but in the Swing plaf. Has any of you had this problem and maybe figured out what is happening here?

   11:28:23,273 [AWT-EventQueue-0] ERROR [is.althingi.styran.utlit.styran.StyranImpl]
   - uncaughtException
   java.lang.NullPointerException
    at javax.swing.plaf.basic.BasicTableUI$Handler.setValueIsAdjusting(Unknown Source)
    at javax.swing.plaf.basic.BasicTableUI$Handler.mouseReleased(Unknown Source)
    at java.awt.AWTEventMulticaster.mouseReleased(Unknown Source)
    at java.awt.Component.processMouseEvent(Unknown Source)
    at javax.swing.JComponent.processMouseEvent(Unknown Source)
    at java.awt.Component.processEvent(Unknown Source)
    at java.awt.Container.processEvent(Unknown Source)
    at java.awt.Component.dispatchEventImpl(Unknown Source)
    at java.awt.Container.dispatchEventImpl(Unknown Source)
    at java.awt.Component.dispatchEvent(Unknown Source)
    at java.awt.LightweightDispatcher.retargetMouseEvent(Unknown Source)
    at java.awt.LightweightDispatcher.processMouseEvent(Unknown Source)
    at java.awt.LightweightDispatcher.dispatchEvent(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.pumpOneEventForFilters(Unknown Source)
    at java.awt.EventDispatchThread.pumpEventsForFilter(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)
+2  A: 

Hi Alfred.

I never had this particular problem but when I get these kind of "hidden" errors I always end up looking the original source code and try to figure out the problem ...

From this source you can see the function that originates the exception:

private void setValueIsAdjusting(boolean flag) {
    table.getSelectionModel().setValueIsAdjusting(flag);
    table.getColumnModel().getSelectionModel().
    setValueIsAdjusting(flag);
}

Can you confirm if your table selection model ; column model ; column selection model aren't null?

bruno conde
How could I? There is an NPE in there, isn't there? But of course the thing is that I can't seem to figure out why one of those is null, because no matter where I put my debugging they are never null!!!!
Alfred B. Thordarson
+2  A: 

I managed to get around the problem!

The thing is that I add a ListSelectionListener to my JTable; in the valueChanged method of my listener I then call scrollRectToVisible and then updateUI, which then results in my exception.

What I did was to add invokeLater around the updateUI call and no more exception!

Like this:

  SwingUtilities.invokeLater(new Runnable() {
    public void run() {
      updateUI();
    }
  });

Now that I have the "answer" to my question (though I'm not sure I still understand why the invokeLater helped?), I think my question wasn't good enough. I didn't provide enough information about my problem for anyone to be able to answer the question. Should I have researched the problem more before I asked? I don't know.

Maybe it is enough that I provide the solution that helped me!

Alfred B. Thordarson
When you call invokeLate(), you're moving the updateUI() function call to the end of the event queue. My guess is that the updateUI() call was trying to access an object that wasn't created yet, but this object is available soon after.
Outlaw Programmer