wood burning stoves
The moose likes Swing / AWT / SWT and the fly likes refreshing container get NullPointerException errors Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login

Win a copy of Introducing JavaFX 8 Programming this week in the JavaFX forum!
JavaRanch » Java Forums » Java » Swing / AWT / SWT
Bookmark "refreshing container get NullPointerException errors" Watch "refreshing container get NullPointerException errors" New topic

refreshing container get NullPointerException errors

Craig Parsons
Ranch Hand

Joined: Jan 28, 2004
Posts: 40
I have a JFrame with some JButtons, JPanels, and layout managers. One of the buttons I have is a reset button to reset everything back to it's original state. When I click on the button I jump down to my buttonHandler method. When it is determined that the reset button was clicked it resets everything OK but after refreshing my container I get a bunch of NullPointerException. In an effert to narrow down the problem I removed all the code regarding this button to what I have below. It seems the layout.layoutContainer(getContentPane()); is causing the problem but I am not sure why. ANY SUGGESTIONS???

These are the errors showing up.
at javax.swing.AbstractButton.fireActionPerformed(AbstractButton.java:1764)
at javax.swing.AbstractButton$ForwardActionEvents.actionPerformed(AbstractButton.java:1817)
at javax.swing.DefaultButtonModel.fireActionPerformed(DefaultButtonModel.java:419)
at javax.swing.DefaultButtonModel.setPressed(DefaultButtonModel.java:257)
at javax.swing.plaf.basic.BasicButtonListener.mouseReleased(BasicButtonListener.java:245)
at java.awt.Component.processMouseEvent(Component.java:5093)
at java.awt.Component.processEvent(Component.java:4890)
at java.awt.Container.processEvent(Container.java:1566)
at java.awt.Component.dispatchEventImpl(Component.java:3598)
at java.awt.Container.dispatchEventImpl(Container.java:1623)
at java.awt.Component.dispatchEvent(Component.java:3439)
at java.awt.LightweightDispatcher.retargetMouseEvent(Container.java:3450)
at java.awt.LightweightDispatcher.processMouseEvent(Container.java:3165)
at java.awt.LightweightDispatcher.dispatchEvent(Container.java:3095)
at java.awt.Container.dispatchEventImpl(Container.java:1609)
at java.awt.Window.dispatchEventImpl(Window.java:1585)
at java.awt.Component.dispatchEvent(Component.java:3439)
at java.awt.EventQueue.dispatchEvent(EventQueue.java:450)
at java.awt.EventDispatchThread.pumpOneEventForHierarchy(EventDispatchThread.java:197)
at java.awt.EventDispatchThread.pumpEventsForHierarchy(EventDispatchThread.java:150)
at java.awt.EventDispatchThread.pumpEvents(EventDispatchThread.java:144)
at java.awt.EventDispatchThread.pumpEvents(EventDispatchThread.java:136)
at java.awt.EventDispatchThread.run(EventDispatchThread.java:99)
Ernest Friedman-Hill
author and iconoclast

Joined: Jul 08, 2003
Posts: 24193

Well, the NullPointerException could come from "layout" being null, so I'd check that first.
In general, you don't want to call layoutContainer() here; you just want to call "validate()".

[Jess in Action][AskingGoodQuestions]
Craig Parsons
Ranch Hand

Joined: Jan 28, 2004
Posts: 40
I added the validate() but was still getting a compiling error. I tried dropping the layout. so that only validate(); was there and it worked. The button worked and there were no more errors. I guess I am still learning the small details of java.
Thanks for your help.

symbol : method validate ()
location: class java.awt.FlowLayout
I agree. Here's the link: http://aspose.com/file-tools
subject: refreshing container get NullPointerException errors
It's not a secret anymore!