2012-08-13 67 views
0

你好,我有消除NullEx的問題...的Android nullexception構造

我設置mContext = context,現在我有錯誤:

Implicit super constructor LinearLayout() is undefined. Must explicitly invoke another constructor 

Constructor call must be the first statement in a constructor 

public DigitalClock(Context context) { 
    mContext=context; 
    this(context, null); 
} 

早些時候線程Android alarm Clock這說明問題。

回答

2

您需要一個超類的構造函數調用。

public DigitalClock(Context context) { 
    super(context); // Add a line like this. 
        // Consult constructor documentation for correct usage. 
    this(context, null); // this line must also be at the top. 
    mContext=context; 
} 
+0

現在我有這樣的錯誤LogCat:pastebin.com/6GzGUcTf – Silesia 2012-08-13 16:18:17

1

我會假設你是擴展視圖,在這種情況下,你至少需要兩個構造函數。

//...Override Constructors...  
public DigitalClock(Context context, AttributeSet attrs) { 
    super(context, attrs); 

} 

public DigitalClock(Context context){ 
    super(context); 

} 

看看是否有幫助。

+0

現在我有這樣的錯誤 LogCat:http://pastebin.com/6GzGUcTf – Silesia 2012-08-13 16:17:50