• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

Null pointer Exception in Basic List UI

 
Greenhorn
Posts: 1
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
 
Marshal
Posts: 79177
377
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
     
    Ranch Hand
    Posts: 4632
    • Mark post as helpful
    • send pies
      Number of slices to send:
      Optional 'thank-you' note:
    • Quote
    • Report post to moderator
    > 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.
     
    Greenhorn
    Posts: 1
    • Mark post as helpful
    • send pies
      Number of slices to send:
      Optional 'thank-you' note:
    • Quote
    • Report post to moderator
    I am not using getGraphics() but calling updateUI() of JList
     
    Greenhorn
    Posts: 2
    • Mark post as helpful
    • send pies
      Number of slices to send:
      Optional 'thank-you' note:
    • Quote
    • Report post to moderator
    Try using
    SwingUtilities.invokeLater(new Runnable() {
    public void run() {
    //Ui updates
    }
    });
     
    Campbell Ritchie
    Marshal
    Posts: 79177
    377
    • Mark post as helpful
    • send pies
      Number of slices to send:
      Optional 'thank-you' note:
    • Quote
    • Report post to moderator
    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.
     
    Greenhorn
    Posts: 1
    • Mark post as helpful
    • send pies
      Number of slices to send:
      Optional 'thank-you' note:
    • Quote
    • Report post to moderator
    Helped me, I ran into the exact same problem.
     
    With a little knowledge, a cast iron skillet is non-stick and lasts a lifetime.
    reply
      Bookmark Topic Watch Topic
    • New Topic