当我尝试在Android Studio中扩展ImageView时,出现了错误信息。

3
在Android Studio中,我试图扩展ImageView小部件,但出现了错误消息“在'android.widget.ImageView'中没有可用的默认构造函数”。如何解决这个错误?
我的代码如下:
包com.example.trendpoints;
import android.content.Context; import android.widget.ImageView; public class CouponImageView extends ImageView {
public CouponImageView(Context c) {

}

}

1个回答

4

你只需要添加super(c);。编译器提示没有可用的默认构造函数。默认构造函数是没有参数的构造函数,如果没有super(c),你试图以隐式方式调用它。

public CouponImageView(Context c) {
       super(c);
}

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接