File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
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
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(
at javax.swing.AbstractButton$ForwardActionEvents.actionPerformed(
at javax.swing.DefaultButtonModel.fireActionPerformed(
at javax.swing.DefaultButtonModel.setPressed(
at javax.swing.plaf.basic.BasicButtonListener.mouseReleased(
at java.awt.Component.processMouseEvent(
at java.awt.Component.processEvent(
at java.awt.Container.processEvent(
at java.awt.Component.dispatchEventImpl(
at java.awt.Container.dispatchEventImpl(
at java.awt.Component.dispatchEvent(
at java.awt.LightweightDispatcher.retargetMouseEvent(
at java.awt.LightweightDispatcher.processMouseEvent(
at java.awt.LightweightDispatcher.dispatchEvent(
at java.awt.Container.dispatchEventImpl(
at java.awt.Window.dispatchEventImpl(
at java.awt.Component.dispatchEvent(
at java.awt.EventQueue.dispatchEvent(
at java.awt.EventDispatchThread.pumpOneEventForHierarchy(
at java.awt.EventDispatchThread.pumpEventsForHierarchy(
at java.awt.EventDispatchThread.pumpEvents(
at java.awt.EventDispatchThread.pumpEvents(
Ernest Friedman-Hill
author and iconoclast

Joined: Jul 08, 2003
Posts: 24195

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
subject: refreshing container get NullPointerException errors
It's not a secret anymore!