简体   繁体   English

当我尝试在Android Studio中扩展ImageView时收到错误消息

[英]I get an error message when I attempt to extend ImageView in Android Studio

In Android Studio I am attempting to extend the ImageView widget, but am getting the error message "there is no default constructor available in 'android.widget.ImageView'" . 在Android Studio中,我试图扩展ImageView小部件,但是收到错误消息“'android.widget.ImageView'中没有可用的默认构造函数”。 How can I resolve this error? 我该如何解决这个错误?

My code is as follows: 我的代码如下:

package com.example.trendpoints; package com.example.trendpoints;

import android.content.Context; import android.content.Context; import android.widget.ImageView; import android.widget.ImageView;

public class CouponImageView extends ImageView { 公共类CouponImageView扩展ImageView {

public CouponImageView(Context c) {

}

} }

you just need to add super(c); 你只需要加上super(c); . The compiler is telling that there is no available default constructor available. 编译器告诉我们没有可用的默认构造函数。 The default constructor is the one without parameters, that without super(c) , you are trying to call in an implicit way 默认构造函数是没有参数的构造函数,没有super(c) ,你试图以隐式方式调用

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

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 我在Android Studio中扩展AppCompatActivity时出错 - Error when i extend AppCompatActivity in Android studio 当我在 Android Studio 中运行虚拟设备时,我收到一条消息 - When I Run Virtual Device In Android Studio I get a message 在片段中添加ImageView时出现Android Studio错误 - Android Studio error when adding ImageView in fragment 如何在 Android Studio 中扩展 SupportMapFragment? - How can I extend SupportMapFragment in Android Studio? 我收到 android 工作室布局和等级错误 - I get android studio layout and grade error 尝试在Android Studio 0.6.1上创建新项目时收到Gradle同步错误 - I get a Gradle sync error when I try to create a new project on Android Studio 0.6.1 我尝试在空对象引用上调用虚拟方法'void android.widget.ImageView.setImageResource(int)' - I got Attempt to invoke virtual method 'void android.widget.ImageView.setImageResource(int)' on a null object reference 添加到请求 DTO 时收到 415 错误消息 - I get an 415 error message when I add to request DTO 当我在 ubuntu 14.04 上运行 android studio 时,我得到了这个 - when i run android studio on ubuntu 14.04 i get this Android - 无法扩展ImageView - Android - Unable to extend ImageView
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM