类型变量 T 与上限折线图,视图



我有以下类:

public class LineChart extends AppCompatActivity{
private LineChart mChart;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_line_chart);
mChart = findViewById(R.id.linechart);
}
}

和一个 XML:

<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_height="match_parent"
android:layout_width="match_parent"
android:id="@+id/relativeLayout">
<com.github.mikephil.charting.charts.LineChart
android:layout_width="match_parent"
android:layout_height="match_parent"
android:id="@+id/linechart">
</com.github.mikephil.charting.charts.LineChart>

我现在的问题是,当我尝试获取带有findViewById(R.id.linechart)的折线图时,出现错误:

错误:(42, 24( 错误:不兼容的类型:类型变量 T 没有唯一的最大实例,其上限为折线图,视图 其中 T 是类型变量: T 扩展 在方法 findViewById(int( 中声明的视图

如果你查看MPAndroidChart Wiki,你会发现我没有做错任何事(我希望(。有人可以告诉我我的错误在哪里。提前致谢

你应该给你的Activity一个不同的名称。

您与名称LineChart有冲突,因此当您执行findViewById(...)查找时,它会认为您要使用您的LineChart而不是您正在使用的库中的那个。

这就是导致不兼容类型消息的原因,因为您的LineChart不会扩展View

最新更新