从JDialog更改为JFrame时发生NullPointerException

错误:线程中的异常“AWT-EventQueue-0”在javax.swing.AbstractButton.fireActionPerformed(Unknown Source)处的ventana.VentanaPrincipal.actionPerformed(VentanaPrincipal.java:136)上的java.lang.NullPointerException .swing.AbstractButton $ Handler.actionPerformed(Unknown Source)at javax.swing.DefaultButtonModel.fireActionPerformed(Unknown Source)at javax.swing.DefaultButtonModel.setPressed(Unknown Source)at javax.swing.plaf.basic.BasicButtonListener.mouseReleased(Unknown源)在java.awt.Component.processEvent(Unknown Source)上的java.awt.Component.processEvent(Unknown Source)在javax.swing.JComponent.processMouseEvent(Unknown Source) java.awt.Component.dispatchEventImpl(Unknown Source)at java.awt.Container.dispatchEventImpl(Unknown Source)at java.awt.Component.dispatchEvent(Unknown Source)at java.awt.LightweightDispatcher.retargetMouseEvent(Unknown Source)at java .awt.LightweightDis java.awt.Window.dispatchEventImpl(Unknown Source)上的java.awt.Container.dispatchEventImpl(Unknown Source)上java.awt.Component的java.awt.LightweightDispatcher.dispatchEvent(Unknown Source)的patcher.processMouseEvent(Unknown Source) java.awt.EventQueue上的java.awt.EventQueue.dispatchEventImpl(Unknown Source)上的dispatchEvent(Unknown Source)java.awt.EventQueue上的$ 200(Unknown Source)java.awt.EventQueue上的$ 3.run(Unknown Source)$ 3 java.security.ProtectionDomain上的java.security.AccessController.doPrivileged(Native Method)上的.run(未知源)java.security.ProtectionDomain上的$ 1.doIntersectionPrivilege(Unknown Source)java.awt.EventQueue上的$ 1.doIntersectionPrivilege(Unknown Source) java.awt.EventQueue上的$ 4.run(Unknown Source)在java.security.ProtectionDomain上的java.security.AccessController.doPrivileged(Native Method)处获得$ 4.run(Unknown Source)。java.awt处的$ 1.doIntersectionPrivilege(Unknown Source)。 EventQueue.dispatchEvent(Unknown Source)at java.awt.EventDispatchThread.pumpOneEv java.awt.EventDispatchThread中的entForFilters(未知源)在java.awt.EventDispatchThread.pumpEventsForFilter(未知源)在java.awt.EventDispatchThread.pumpEventsForHierarchy(未知源)在java.awt.EventDispatchThread.pumpEvents(未知源)在java.awt.EventDispatchThread.pumpEvents(未知来源)'


您必须确保在切换窗口时已经实例化了新的JDialogJFrame

JDialog newDialog = new JDialog();
JFrame newFrame = new JFrame();

如果您在实例化它们之前尝试切换到newDialognewFrame ,您将得到NullPointerException 。 另外,你应该阅读使用多个JFrames,好/坏实践?

链接地址: http://www.djcxy.com/p/73437.html

上一篇: NullPointerException when making a change from a JDialog to a JFrame

下一篇: NullPointerException in Java Table Selecting rows