This bug referrers to my post in #2450
Following testcase:
while(true) {
entry = new Entry(index, value); // Entry object
indexOfDataSet = mLineDate.getIndexOfDataSet(mPowerLineDataSet);
mLineDate.addEntry(entry, indexOfDataSet); // LineData object
mChart.setData(mLineDate); // LineChart object
mChart.notifyDataSetChanged();
mChart.invalidate();
}
Following crash occur with a more complicated scenario and multiple lines in the chart:
--------- beginning of crash
E/AndroidRuntime: FATAL EXCEPTION: main
Process: com.bennoss.myergometertrainer, PID: 3610
java.lang.IndexOutOfBoundsException: Index: 2, Size: 2
at java.util.ArrayList.get(ArrayList.java:411)
at com.github.mikephil.charting.renderer.LegendRenderer.renderLegend(LegendRenderer.java:377)
at com.github.mikephil.charting.charts.BarLineChartBase.onDraw(BarLineChartBase.java:28
Process: com.bennoss.myergometertrainer, PID: 3610
1)
at android.view.View.draw(View.java:17071)
at android.view.View.updateDisplayListIfDirty(View.java:16053)
at android.view.ViewGroup.recreateChildDisplayList(ViewGroup.java:3748)
at android.view.ViewGroup.dispatchGetDisplayList(ViewGroup.java:3728)
at android.view.View.updateDisplayListIfDirty(View.java:16016)
at android.view.ViewGroup.recreateChildDisplayList(ViewGroup.java:3748)
at android.view.ViewGroup.dispatchGetDisplayList(ViewGroup.java:3728)
at android.view.View.updateDisplayListIfDirty(View.java:16016)
at android.view.ViewGroup.recreateChildDisplayList(ViewGroup.java:3748)
at android.view.ViewGroup.dispatchGetDisplayList(ViewGroup.java:3728)
at android.view.View.updateDisplayListIfDirty(View.java:16016)
at android.view.ViewGroup.recreateChildDisplayList(ViewGroup.java:3748)
at android.view.ViewGroup.dispatchGetDisplayList(ViewGroup.java:3728)
at android.view.View.updateDisplayListIfDirty(View.java:16016)
at android.view.ViewGroup.recreateChildDisplayList(ViewGroup.java:3748)
at android.view.ViewGroup.dispatchGetDisplayList(ViewGroup.java:3728)
at android.view.View.updateDisplayListIfDirty(View.java:16016)
at android.view.ViewGroup.recreateChildDisplayList(ViewGroup.java:3748)
at android.view.ViewGroup.dispatchGetDisplayList(ViewGroup.java:3728)
at android.view.View.updateDisplayListIfDirty(View.java:16016)
at android.view.ViewGroup.recreateChildDisplayList(ViewGroup.java:3748)
at android.view.ViewGroup.dispatchGetDisplayList(ViewGroup.java:3728)
at android.view.View.updateDisplayListIfDirty(View.java:16016)
at android.view.ViewGroup.recreateChildDisplayList(ViewGroup.java:3748)
at android.view.ViewGroup.dispatchGetDisplayList(ViewGroup.java:3728)
at android.view.View.updateDisplayListIfDirty(View.java:16016)
at android.view.ThreadedRenderer.updateViewTreeDisplayList(ThreadedRenderer.java:656)
at android.view.ThreadedRenderer.updateRootDisplayList(ThreadedRenderer.java:662)
at android.view.ThreadedRenderer.draw(ThreadedRenderer.java:770)
at android.view.ViewRootImpl.draw(ViewRootImpl.java:2796)
at android.view.ViewRootImpl.performDraw(ViewRootImpl.java:2604)
at android.view.ViewRootImpl.performTraversals(ViewRootImpl.java:2211)
at android.view.ViewRootImpl.doTraversal(ViewRootImpl.java:1246)
at android.view.ViewRootImpl$TraversalRunnable.run(ViewRootImpl.java:6301)
at android.view.Choreographer$CallbackRecord.run(Choreographer.java:871)
at android.view.Choreographer.doCallbacks(Choreographer.java:683)
at android.view.Choreographer.doFrame(Choreographer.java:619)
at android.view.Choreographer$FrameDisplayEventReceiver.run(Choreographer.java:857)
at android.os.Handler.handleCallback(Handler.java:751)
at android.os.Handler.dispatchMessage(Handler.java:95)
at android.os.Looper.loop(Looper.java:154)
at android.app.ActivityThread.main(ActivityThread.java:6077)
at java.lang.reflect.Method.invoke(Native Method)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:866)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:756)
OR
java.lang.IndexOutOfBoundsException: Index: 1, Size: 1
java.lang.IndexOutOfBoundsException: Index: 2, Size: 0
The exception can't be caught and the whole app crashes.
It seams that invalidate() hasn't been finished completely before new data was set and triggers therefore the exception.
One temporary workaround is a Thread.sleep(150); or more after calling invalidate().
50ms is not enough. Even with 100ms the exception gets thrown after a while.
My personal favorite solution would be, that I could just catch the exception with a try block around invalidate() OR that the update of the cart would just not been performed if the exception occurred (ignore update via invalidate and continue).
I'm using MPAndroidChart:v3.1.0.
This bug referrers to my post in #2450
Following testcase:
Following crash occur with a more complicated scenario and multiple lines in the chart:
OR
The exception can't be caught and the whole app crashes.
It seams that
invalidate()hasn't been finished completely before new data was set and triggers therefore the exception.One temporary workaround is a
Thread.sleep(150);or more after callinginvalidate().50ms is not enough. Even with 100ms the exception gets thrown after a while.
My personal favorite solution would be, that I could just catch the exception with a try block around
invalidate()OR that the update of the cart would just not been performed if the exception occurred (ignore update via invalidate and continue).I'm using MPAndroidChart:v3.1.0.