0

您好,我对消除 NullEx 有疑问...

我设置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闹钟显示问题。

4

2 回答 2

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;
}
于 2012-08-13T15:57:11.380 回答
1

我假设您正在扩展 View,在这种情况下,您至少需要两个构造函数。

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

}

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

}

看看是否有帮助。

于 2012-08-13T15:57:12.047 回答