类型变量 T 与上限 LineChart,View
type variable T with upper bounds LineChart,View
我有以下 class:
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)
获取折线图时,出现错误:
Error:(42, 24) error: incompatible types: no unique maximal instance exists for type variable T with upper bounds LineChart,View
where T is a type-variable:
T extends View declared in method findViewById(int)
如果您查看 MPAndroidChart Wiki,您会发现我没有做错任何事(希望如此)。有人可以告诉我我的错误在哪里吗?提前致谢
你应该给你的 Activity
一个不同的名字。
您与名称 LineChart
有冲突,因此当您执行 findViewById(...)
查找时,它认为您想使用您的 LineChart
而不是您正在使用的库中的那个.
这就是导致不兼容类型消息的原因,因为您的 LineChart
没有扩展 View
。
我有以下 class:
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)
获取折线图时,出现错误:
Error:(42, 24) error: incompatible types: no unique maximal instance exists for type variable T with upper bounds LineChart,View where T is a type-variable: T extends View declared in method findViewById(int)
如果您查看 MPAndroidChart Wiki,您会发现我没有做错任何事(希望如此)。有人可以告诉我我的错误在哪里吗?提前致谢
你应该给你的 Activity
一个不同的名字。
您与名称 LineChart
有冲突,因此当您执行 findViewById(...)
查找时,它认为您想使用您的 LineChart
而不是您正在使用的库中的那个.
这就是导致不兼容类型消息的原因,因为您的 LineChart
没有扩展 View
。