This week's giveaway is in the Android forum.
We're giving away four copies of Android Security Essentials Live Lessons and have Godfrey Nolan on-line!
See this thread for details.
The moose likes Swing / AWT / SWT and the fly likes Null pointer Exception in Basic List UI Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Android Security Essentials Live Lessons this week in the Android forum!
JavaRanch » Java Forums » Java » Swing / AWT / SWT
Bookmark "Null pointer Exception in Basic List UI" Watch "Null pointer Exception in Basic List UI" New topic
Author

Null pointer Exception in Basic List UI

naresh abcdef
Greenhorn

Joined: Feb 04, 2005
Posts: 1
Hello All

I am facing a problem in Javax swing while painting GUI. I am showing a dialog by using SwingUtilities.invokeLater() and some processing is done in background and based upon that I am updating my GUI in background. After the painting and updating in background is complete I remove the dialog. But in the meantime the following exception is coming. One point worth mentioning here is that the problem's frequency is very high on some desktops and very low on some systems.

The exception comes in any method call of BasicListUI






java.lang.NullPointerException
at javax.swing.plaf.basic.BasicListUI.getHeight(Unknown Source)

at javax.swing.plaf.basic.BasicListUI.paint(Unknown Source)

at javax.swing.plaf.ComponentUI.update(Unknown Source)

at javax.swing.JComponent.paintComponent(Unknown Source)

at javax.swing.JComponent.paint(Unknown Source)

at javax.swing.JComponent.paintWithOffscreenBuffer(Unknown Source)

at javax.swing.JComponent.paintDoubleBuffered(Unknown Source)

at javax.swing.JComponent._paintImmediately(Unknown Source)

at javax.swing.JComponent.paintImmediately(Unknown Source)

at javax.swing.RepaintManager.paintDirtyRegions(Unknown Source)

at javax.swing.SystemEventQueueUtilities$ComponentWorkRequest.run(Unknown Source)

at java.awt.event.InvocationEvent.dispatch(Unknown Source)

at java.awt.EventQueue.dispatchEvent(Unknown Source)

at java.awt.EventDispatchThread.pumpOneEventForHierarchy(Unknown Source)

at java.awt.EventDispatchThread.pumpEventsForHierarchy(Unknown Source)

at java.awt.EventDispatchThread.pumpEventsForHierarchy(Unknown Source)

at java.awt.Dialog$1.run(Unknown Source)

at java.awt.Dialog.show(Unknown Source)

at java.awt.Component.show(Unknown Source)

at java.awt.Component.setVisible(Unknown Source)

at com.mgoyal.ProgressDialog.showProgressDialog(ProgressDialogUI.java:164)

at com.mgoyal.MainController.run(MainController.java:1631)

at java.awt.event.InvocationEvent.dispatch(Unknown Source)

at java.awt.EventQueue.dispatchEvent(Unknown Source)

at java.awt.EventDispatchThread.pumpOneEventForHierarchy(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)




java.lang.NullPointerException
at javax.swing.plaf.basic.BasicListUI.paintCell(Unknown Source)

at javax.swing.plaf.basic.BasicListUI.paint(Unknown Source)

at javax.swing.plaf.ComponentUI.update(Unknown Source)

at javax.swing.JComponent.paintComponent(Unknown Source)

at javax.swing.JComponent.paint(Unknown Source)

at javax.swing.JComponent.paintWithOffscreenBuffer(Unknown Source)

at javax.swing.JComponent.paintDoubleBuffered(Unknown Source)

at javax.swing.JComponent._paintImmediately(Unknown Source)

at javax.swing.JComponent.paintImmediately(Unknown Source)

at javax.swing.RepaintManager.paintDirtyRegions(Unknown Source)

at javax.swing.SystemEventQueueUtilities$ComponentWorkRequest.run(Unknown Source)

at java.awt.event.InvocationEvent.dispatch(Unknown Source)

at java.awt.EventQueue.dispatchEvent(Unknown Source)

at java.awt.EventDispatchThread.pumpOneEventForHierarchy(Unknown Source)

at java.awt.EventDispatchThread.pumpEventsForHierarchy(Unknown Source)

at java.awt.EventDispatchThread.pumpEventsForHierarchy(Unknown Source)

at java.awt.Dialog$1.run(Unknown Source)

at java.awt.Dialog.show(Unknown Source)

at java.awt.Component.show(Unknown Source)

at java.awt.Component.setVisible(Unknown Source)

at com.mgoyal.ProgressDialog.showProgressDialog(ProgressDialogUI.java:164)

at com.mgoyal.MainController.run(MainController.java:1631)

at java.awt.event.InvocationEvent.dispatch(Unknown Source)

at java.awt.EventQueue.dispatchEvent(Unknown Source)

at java.awt.EventDispatchThread.pumpOneEventForHierarchy(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)





I am not using BasicListUI at all in my code but a JList is being used which I repaint in the background by calling updateUI() method of JList
Campbell Ritchie
Sheriff

Joined: Oct 13, 2005
Posts: 38075
    
  22
I am sure I have written about NullPointerException before, and I shall repeat myself.

BTW: Is there an FAQ on the Ranch about NullPointerException?

It usually means you are trying to use an object which does not exist. Unless you have a line like:-

NullPointer, (like the other two exceptions I keep going on about, ArithmeticException and XYZIndexOutOfBoundsException) means there is an error in your coding somewhere.

  • Find the line number where your exception occurs. You should be able to read that from the error message.
  • Look at that line and count every object which is, or might be, used in it.
  • Enter a line, 1 line before that line, where you print out all these objects: something like this:

  • System.out.printf("ObjectA: %s ObjectB: %s ObjectC %s%n", objectA, objectB, objectC);//test
  • Look at your printout. An object with details, eg class name and hash code, exists.
  • An object without details, doesn't exist. It will usually say "ObjectC: null"
  • Go back over the history of any "null" objects, and make sure they have actually been instantiated.
  • Voila. Easy.

  • Two likely reasons for a null object:
  • 1: forgetting to instantiate it in the first place
  • 2: Obscuring (is that the right term) it by inadvertently re-declaring it as a local variable.

  • I read somewhere, I forget where, that one spends very little time correcting errors found in debugging. It is finding them that is the problem.

    CR
    Michael Dunn
    Ranch Hand

    Joined: Jun 09, 2003
    Posts: 4632
    > After the painting and updating in background is complete.....

    are you using getGraphics()
    if so, that is probably your problem.

    post a small sample program that demonstrates the behavior.
    nareshh lakkavarapuu
    Greenhorn

    Joined: Feb 06, 2006
    Posts: 1
    I am not using getGraphics() but calling updateUI() of JList
    Binoy Joseph
    Greenhorn

    Joined: Oct 10, 2005
    Posts: 2
    Try using
    SwingUtilities.invokeLater(new Runnable() {
    public void run() {
    //Ui updates
    }
    });
    Campbell Ritchie
    Sheriff

    Joined: Oct 13, 2005
    Posts: 38075
        
      22
    Welcome to JavaRanch Binoy Joseph

    But how useful your answer will be on a thread from over two years ago, I am not sure. Please look at this FAQ.
    Jeremy Jinks
    Greenhorn

    Joined: May 24, 2011
    Posts: 1
    Helped me, I ran into the exact same problem.
     
    It is sorta covered in the JavaRanch Style Guide.
     
    subject: Null pointer Exception in Basic List UI
     
    Similar Threads
    Table sorter going nuts once added another itam
    JTable throwing exception when loaded
    GUI update error
    Unknown Source exception
    making sense of exception