2012-08-13 61 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