A
A
Awesome_T2020-07-05 10:28:30
Java
Awesome_T, 2020-07-05 10:28:30

How to correctly create an object of the BarDataSet class?

I'm trying to create a chart using the MPAndroidChart library. Input numeric data from SQLlite, convert to BarData? what does the constructor of this class look like?

List<Integer> WaterSpentArrayList;
WaterSpentArrayList = db.getWaterSpent();
    ArrayList<BarEntry> EntryData = new ArrayList<>();
    if ( WaterSpentArrayList.size()==0) {
    }else {
        for (int i = 0; i < WaterSpentArrayList.size(); i++) {
            EntryData.add(new BarEntry(WaterSpentArrayList.get(i), i));
        }
        Log.e(TAG, "Data:  " + EntryData);
        BarDataSet bardataset = new BarDataSet(EntryData, "WaterSpentArrayList");
        BarData data = new BarData((IBarDataSet) DataTimeSpentArrayList, bardataset);
        barChart.setData(data)


E/CleanersActivity: SimpleEntry : [Entry, x: 20.0 y: 0.0, Entry, x: 29.0 y: 1.0, Entry, x: 35.0 y: 2.0, Entry, x: 22.0 y: 3.0, Entry, x: 20.0 y: 4.0, Entry, x: 29.0 y: 5.0, Entry, x: 35.0 y: 6.0, Entry, x: 22.0 y: 7.0, Entry, x: 20.0 y: 8.0, Entry, x: 29.0 y: 9.0, Entry, x : 35.0 y: 10.0, Entry, x: 22.0 y: 11.0, Entry, x: 20.0 y: 12.0, Entry, x: 29.0 y: 13.0, Entry, x: 35.0 y: 14.0, Entry, x: 22.0 y: 15.0 ] D/AndroidRuntime: Shutting down VM --------- beginning of crash E/AndroidRuntime: FATAL EXCEPTION: main Process: PID: 28873 java.lang.RuntimeException: Unable to start activity ComponentInfo{CleanersActivity}: java. lang.ClassCastException: java.util.ArrayList cannot be cast to com.github.mikephil.charting.interfaces.datasets.IBarDataSet

Answer the question

In order to leave comments, you need to log in

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question