以下是我的应用程序被系统缓存清除时出现的错误。 每当我在应用程序之间切换时,我都会收到此错误 所以,如果你有任何知道这个错误或MPandroidchart库 请帮忙。
java.lang.IndexOutOfBoundsException: Invalid index 0, size is 0
11-09 19:34:42.397 E/AndroidRuntime( 5201): at
java.util.ArrayList.throwIndexOutOfBoundsException(ArrayList.java:255)
11-09 19:34:42.397 E/AndroidRuntime( 5201): at
java.util.ArrayList.get(ArrayList.java:308)
11- 09 19:34:42.397 E/AndroidRuntime( 5201): at
com.github.mikephil.charting.data.DataSet.getEntryForIndex(DataSet.java:286)
11-09 19:34:42.397 E/AndroidRuntime( 5201): at
以下是在折线图上绘制数据的代码 我已经尝试了很多谷歌和GIt,但无法找到任何解决方案
public void setData()
{
mChart.getAxisLeft().setDrawGridLines(false);
mChart.getXAxis().setDrawGridLines(false);
mChart.getAxisRight().setDrawGridLines(false);
mChart.setOnChartValueSelectedListener(this);
mChart.fitScreen();
Description description = mChart.getDescription();
description.setText("");
setLineChartData();
XAxis xAxis = mChart.getXAxis();
xAxis.setPosition(XAxis.XAxisPosition.BOTH_SIDED);
xAxis.setValueFormatter(new IAxisValueFormatter() {
@Override
public String getFormattedValue(float value, AxisBase axis) {
Log.d("VALUESSS>>",value+"");
// arrayListDate
return mMonths[(int) value % mMonths.length];
}
});
}
private ArrayList<Entry> setYAxisValues(){
ArrayList<Entry> yVals = new ArrayList<>();
for (int i=0;i<SplashScreen.arrayListPrice.size();i++)
{
yVals.add(new Entry(i, SplashScreen.arrayListPrice.get(i)));
}
return yVals;
}
private void setLineChartData() {
ArrayList<Entry> yVals = setYAxisValues();
// create a dataset and give it a type
set1 = new LineDataSet(yVals, "Zenith Bitcoin");
set1.setFillAlpha(110);
set1.setFillColor(Color.RED);
set1.setColor(Color.parseColor("#1caf9a"));
set1.setCircleColor(Color.BLUE);
set1.setLineWidth(0.5f);
set1.setLabel(String.valueOf(Html.fromHtml("<h1> Zenith Bitcoin</h1> ")));
set1.setCircleRadius(4f);
set1.setDrawCircleHole(true);
set1.setValueTextSize(9f);
set1.setDrawFilled(true);
Drawable drawable = ContextCompat.getDrawable(this, R.drawable.fade_red);
if (Integer.valueOf(android.os.Build.VERSION.SDK)>17)
set1.setFillDrawable(drawable);
ArrayList<ILineDataSet> dataSets = new ArrayList<>();
dataSets.add(set1); // add the datasets
// create a data object with the datasets
LineData data = new LineData(dataSets);
mChart.setTouchEnabled(true);
mChart.setPinchZoom(false);
mChart.setScaleEnabled(false);
//mChart.setViewPortOffsets(55f, 25f, 115f, 125f);
mChart.setDrawMarkers(true);
//mChart.setExtraOffsets(10f, 10f, 10f, 10f);
mChart.getAxisRight().setXOffset(15);
mChart.getAxisLeft().setXOffset(15);
mChart.getAxisRight().setDrawAxisLine(false);
mChart.getAxisLeft().setDrawAxisLine(false);
CustomMarkerView mv = new CustomMarkerView (Dashboard.this, R.layout.custom_marker_view_layout);
mChart.setMarkerView(mv);
// set data
mChart.clear();
mChart.setData(data);
}
任何帮助?
答案 0 :(得分:0)
您必须调试它,因为它不是库的错误,而是在您提供条目时的值。确保SplashScreen.arrayListPrice.get(i)
不是null
。