Forums Register Login

refreshing container get NullPointerException errors

+Pie Number of slices to send: Send
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)
+Pie Number of slices to send: Send
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()".
+Pie Number of slices to send: Send
Thanks,
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
layout.validate();
^
Craig
Whoever got anywhere by being normal? Just ask this exceptional tiny ad:
a bit of art, as a gift, the permaculture playing cards
https://gardener-gift.com


reply
reply
This thread has been viewed 1197 times.
Similar Threads
How to convert arabic numbers received from JTextField to a Double?
Disappearing object
how to use parseInt()
org.omg.CORBA.COMM_FAILURE: vmcid: SUN minor code: 201
How to print list of Files?
More...

All times above are in ranch (not your local) time.
The current ranch time is
Mar 29, 2024 08:17:22.