android - 类型参数 t 具有不兼容的上界 View 和 ListView

标签 android android-studio android-layout listview compiler-errors

初始化 ListView 时出现错误 findViewById(R.id.listview)

error: incompatible types: no unique maximal instance exists for type variable T with upper bounds ListView,View where T is a type-variable: T extends View declared in method findViewById(int)

public class ListView extends AppCompatActivity {
    ListView listview;
    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_list_view);

        listview = findViewById(R.id.listview);

    }
}

最佳答案

将您的 Activity 名称重命名为 ListViewListViewActivity

因为当你在声明 ListView listview; 时,listview 变成了 Activity 类型。

关于android - 类型参数 t 具有不兼容的上界 View 和 ListView ,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/58471098/

相关文章:

android - AlertDialog 不适用于自定义布局

android - 通过 adb shell 命令打开摄像机

android-studio - java.lang.IllegalArgumentException : No OpKernel was registered to support Op 'GatherV2' with these attrs.

android - 打包 APK 期间文件重复

java - setContentView() 与 GLSurfaceView 一起使用时崩溃

android - 使用android API = 8在背景图像上旋转透明png图像

java - android.content.res.Resources$NotFoundException : Resource ID #0x88a6fd

java - 安全异常:权限被拒绝

Android Studio 1.3 SVG 到 png 的转换

android-studio - Android Studio 模拟器参数