Home > OS >  Cannot access '<init>': it is protected in 'Entry'
Cannot access '<init>': it is protected in 'Entry'

Time:12-11

I am trying to access the dataset

import com.github.mikephil.charting.data.PieData
import com.github.mikephil.charting.data.PieDataSet
import com.github.mikephil.charting.data.Entry

    //Create a dataset
    val dataArray = ArrayList<Entry>()
    dataArray.add(Entry(38f))
    dataArray.add(Entry(14f))
    dataArray.add(Entry(14f))
    dataArray.add(Entry(34f))
    val dataSet = PieDataSet(dataArray, "")
    dataSet.valueTextSize=20f
    dataSet.valueTextColor=Color.WHITE

but that result's into an error.

**Cannot access '<init>': it is protected in 'Entry'**

Why isn't it working? How can this be workaround.

CodePudding user response:

I don't use MPAndroidChart, but a quick glance at the Github page shows that Entry requires two floats passed to the constructor for X and Y. Since you're making a PieChart, I think you need to use PieEntry instead, which takes a single float passed to the constructor.

  • Related