0

我从一个有另一个类扩展它的类内部得到一个空指针。扩展它的类有一条super线,这条线导致它被设置为空......

具有空错误的类(启动器):

private Frame frame;

public Launcher(Frame frame, int id) {
    this.frame = frame;

得到错误的行(在启动器中):

frame.ThreeD(); //THIS IS LINE 77

在框架类中

public void ThreeDLauncher() {      
    new Launcher(this, 0);
}

这是另一个创建空值的类:

public class Options extends Launcher {

public Options() {
    super(null, 1);
}

所以我需要重新安排它,这样它就不会再创建这个 null 但它不会让我在那里什么都没有?它也无法更改 Launcher 类中设置的内容。

我怎样才能解决这个问题?

更新 这是详细的错误:

Exception in thread "AWT-EventQueue-0" java.lang.NullPointerException
    at ThreeD.Launcher$1.actionPerformed(Launcher.java:77)
    at javax.swing.AbstractButton.fireActionPerformed(AbstractButton.java:2028)
    at javax.swing.AbstractButton$Handler.actionPerformed(AbstractButton.java:2351)
    at javax.swing.DefaultButtonModel.fireActionPerformed(DefaultButtonModel.java:387)
    at javax.swing.DefaultButtonModel.setPressed(DefaultButtonModel.java:242)
    at javax.swing.plaf.basic.BasicButtonListener.mouseReleased(BasicButtonListener.java:236)
    at java.awt.Component.processMouseEvent(Component.java:6373)
    at javax.swing.JComponent.processMouseEvent(JComponent.java:3267)
    at java.awt.Component.processEvent(Component.java:6138)
    at java.awt.Container.processEvent(Container.java:2085)
    at java.awt.Component.dispatchEventImpl(Component.java:4735)
    at java.awt.Container.dispatchEventImpl(Container.java:2143)
    at java.awt.Component.dispatchEvent(Component.java:4565)
    at java.awt.LightweightDispatcher.retargetMouseEvent(Container.java:4621)
    at java.awt.LightweightDispatcher.processMouseEvent(Container.java:4282)
    at java.awt.LightweightDispatcher.dispatchEvent(Container.java:4212)
    at java.awt.Container.dispatchEventImpl(Container.java:2129)
    at java.awt.Window.dispatchEventImpl(Window.java:2478)
    at java.awt.Component.dispatchEvent(Component.java:4565)
    at java.awt.EventQueue.dispatchEventImpl(EventQueue.java:679)
    at java.awt.EventQueue.access$000(EventQueue.java:85)
    at java.awt.EventQueue$1.run(EventQueue.java:638)
    at java.awt.EventQueue$1.run(EventQueue.java:636)
    at java.security.AccessController.doPrivileged(Native Method)
    at java.security.AccessControlContext$1.doIntersectionPrivilege(AccessControlContext.java:87)
    at java.security.AccessControlContext$1.doIntersectionPrivilege(AccessControlContext.java:98)
    at java.awt.EventQueue$2.run(EventQueue.java:652)
    at java.awt.EventQueue$2.run(EventQueue.java:650)
    at java.security.AccessController.doPrivileged(Native Method)
    at java.security.AccessControlContext$1.doIntersectionPrivilege(AccessControlContext.java:87)
    at java.awt.EventQueue.dispatchEvent(EventQueue.java:649)
    at java.awt.EventDispatchThread.pumpOneEventForFilters(EventDispatchThread.java:296)
    at java.awt.EventDispatchThread.pumpEventsForFilter(EventDispatchThread.java:211)
    at java.awt.EventDispatchThread.pumpEventsForHierarchy(EventDispatchThread.java:201)
    at java.awt.EventDispatchThread.pumpEvents(EventDispatchThread.java:196)
    at java.awt.EventDispatchThread.pumpEvents(EventDispatchThread.java:188)
    at java.awt.EventDispatchThread.run(EventDispatchThread.java:122)
4

2 回答 2

0

看起来非空Frame是必不可少的。因此,Options类构造函数需要提供一个框架。也许是这样的:

public class Options extends Launcher {
    public Options(Frame frame) {
        super(frame, 1);
    }
    ...
于 2012-05-20T13:14:38.067 回答
0

Launcher 需要另一个不需要传入 Frame 的构造函数。

Public Launcher(int id) {
   this.frame = new Frame();
   this.id = id;
}

这可能是 null 的来源。

于 2012-05-20T13:24:18.993 回答