2012-05-20 141 views
0

我從裏面有一個空指針有另一個類擴展它。即獲得誤差(在啓動修復空指針錯誤

private Frame frame; 

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

線:類擴展它具有super行,此行是導致它被設置爲空...

類與空錯誤(發射器) ):

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

在幀類

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

這裏是創建空另一個類:

public class Options extends Launcher { 

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

,所以我需要重新安排它,所以它不再創建這個空,但它不會讓我有什麼呢?它也不能改變Launcher類中設置的內容。

我該如何解決這個問題?

UPDATE 這是詳細的錯誤:

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) 
+1

什麼是你的'NullPointerException'的完整堆棧跟蹤? – Jeffrey

+0

對於某些問題,代碼片段不足以提供有效的判斷調用。好像這就是這種情況,請提供完整的代碼,正如@Jeffrey所述,堆棧跟蹤:-)你的'發射器類的77號線在哪裏? –

+0

我剛更新了它 – core16

回答

0

它看起來像一個非空Frame是必不可少的。因此,類構造函數需要提供一個框架。也許是這樣的:

public class Options extends Launcher { 
    public Options(Frame frame) { 
     super(frame, 1); 
    } 
    ... 
+0

我試過,但是我仍然得到一個空 – core16

+0

當你調用'Options'構造函數......當然你必須提供一個非空的'Frame'參數。 –

0

啓動需要另一個構造不需要幀傳入

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

這也許就是空是來自。