0

I have the following 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);
  }
}

And an 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>

My problem now is that when i try to get the Line Chart with findViewById(R.id.linechart) i get the error:

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)

If you look in the MPAndroidChart Wiki you will see that i did nothing wrong (i hope). Can someone tell me please where my mistake is. Thanks in advance

CodeChimp
  • 4,745
  • 6
  • 45
  • 61
niv
  • 15
  • 1
  • 6

1 Answers1

2

You should give your Activity a different name.

You have a conflict with the name LineChart so when you do the findViewById(...) lookup it thinks you want to use your LineChart instead of the one from the library you are using.

This is what is causing the incompatible types message since your LineChart does not extend View.

George Mulligan
  • 11,813
  • 6
  • 37
  • 50