【问题标题】:I get an error message when I attempt to extend ImageView in Android Studio尝试在 Android Studio 中扩展 ImageView 时收到错误消息
【发布时间】:2015-02-08 22:52:47
【问题描述】:

在 Android Studio 中,我尝试扩展 ImageView 小部件,但收到错误消息“'android.widget.ImageView' 中没有可用的默认构造函数”。我该如何解决这个错误?

我的代码如下:

包 com.example.trendpoints;

导入 android.content.Context; 导入android.widget.ImageView;

公共类 CouponImageView 扩展 ImageView {

public CouponImageView(Context c) {

}

}

【问题讨论】:

    标签: java android


    【解决方案1】:

    您只需添加super(c);。编译器告诉没有可用的默认构造函数可用。默认构造函数是没有参数的,没有super(c),你试图以一种隐式的方式调用

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

    【讨论】:

      猜你喜欢
      • 2021-06-13
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2020-03-07
      • 1970-01-01
      • 1970-01-01
      • 2018-03-09
      • 1970-01-01
      相关资源
      最近更新 更多