PhilJay / MPAndroidChart

A powerful 🚀 Android chart view / graph view library, supporting line- bar- pie- radar- bubble- and candlestick charts as well as scaling, panning and animations.
Other
37.63k stars 9.02k forks source link

XAxisRenderer.drawLabels() - java.lang.ArrayIndexOutOfBoundsException #2321

Open oxoocoffee opened 8 years ago

oxoocoffee commented 8 years ago

I am on beta1 tag and found this reproducible issue where

mXAxis.mCenteredEntries is empty causing blow out. I am basing my code from your sample. DynamicalAddingActivity.java

positions[i] = mXAxis.mCenteredEntries[i / 2]; <------

In my case I do not add any data after starting my app so chart is empty. Then I try to pinch with my fingers on empty chart (Found this by accident :)

Here is full stack

E/AndroidRuntime: FATAL EXCEPTION: main Process: com.tti.rfchart, PID: 29255 java.lang.ArrayIndexOutOfBoundsException: length=0; index=0 at com.github.mikephil.charting.renderer.XAxisRenderer.drawLabels(XAxisRenderer.java:189) at com.github.mikephil.charting.renderer.XAxisRenderer.renderAxisLabels(XAxisRenderer.java:129) at com.github.mikephil.charting.charts.BarLineChartBase.onDraw(BarLineChartBase.java:268) at android.view.View.draw(View.java:16178) at android.view.View.updateDisplayListIfDirty(View.java:15174) at android.view.ViewGroup.recreateChildDisplayList(ViewGroup.java:3593) at android.view.ViewGroup.dispatchGetDisplayList(ViewGroup.java:3573) at android.view.View.updateDisplayListIfDirty(View.java:15134) at android.view.ViewGroup.recreateChildDisplayList(ViewGroup.java:3593) at android.view.ViewGroup.dispatchGetDisplayList(ViewGroup.java:3573) at android.view.View.updateDisplayListIfDirty(View.java:15134) at android.view.ViewGroup.recreateChildDisplayList(ViewGroup.java:3593) at android.view.ViewGroup.dispatchGetDisplayList(ViewGroup.java:3573) at android.view.View.updateDisplayListIfDirty(View.java:15134) at android.view.ViewGroup.recreateChildDisplayList(ViewGroup.java:3593) at android.view.ViewGroup.dispatchGetDisplayList(ViewGroup.java:3573) at android.view.View.updateDisplayListIfDirty(View.java:15134) at android.view.ViewGroup.recreateChildDisplayList(ViewGroup.java:3593) at android.view.ViewGroup.dispatchGetDisplayList(ViewGroup.java:3573) at android.view.View.updateDisplayListIfDirty(View.java:15134) at android.view.ViewGroup.recreateChildDisplayList(ViewGroup.java:3593) at android.view.ViewGroup.dispatchGetDisplayList(ViewGroup.java:3573) at android.view.View.updateDisplayListIfDirty(View.java:15134) at android.view.ViewGroup.recreateChildDisplayList(ViewGroup.java:3593) at android.view.ViewGroup.dispatchGetDisplayList(ViewGroup.java:3573) at android.view.View.updateDisplayListIfDirty(View.java:15134) at android.view.ViewGroup.recreateChildDisplayList(ViewGroup.java:3593) at android.view.ViewGroup.dispatchGetDisplayList(ViewGroup.java:3573) at android.view.View.updateDisplayListIfDirty(View.java:15134) at android.view.ThreadedRenderer.updateViewTreeDisplayList(ThreadedRenderer.java:281) at android.view.ThreadedRenderer.updateRootDisplayList(ThreadedRenderer.java:287) at android.view.ThreadedRenderer.draw(ThreadedRenderer.java:322) at android.view.ViewRootImpl.draw(ViewRootImpl.java:2735) at android.view.ViewRootImpl.performDraw(ViewRootImpl.java:2553) at android.view.ViewRootImpl.performTraversals(ViewRootImpl.java:2172) at android.view.ViewRootImpl.doTraversal(ViewRootImpl.java:1196) at android.view.ViewRootImpl$TraversalRunnable.run(ViewRootImpl.java:6193) at android.view.Choreographer$CallbackRecord.run(Choreographer.java:858) at android.view.Choreographer.doCallbacks(Choreographer.java:670) at android.view.Choreographer.doFrame(Choreographer.java:606) at android.view.Choreographer$FrameDisplayEventReceiver.run(Choreographer.java:844) at android.os.Handler.handleCallback(Handler.java:742) at android.os.Handler.dispatchMessage(Handler.java:97) at android.os.Looper.loop(Looper.java:148) at android.app.ActivityThread.main(ActivityThread.java:5460) at java.lang.reflect.Method.invoke(Native Method) at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:726) at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:616)

oxoocoffee commented 8 years ago

Now I noticed that his happens even when I have data in chart.

jarLiao commented 8 years ago

Hey, how did you solve the problem? Can you please share?

oxoocoffee commented 8 years ago

I did not have time to fix this. I will look at this by end off the weekend when I am done with other tasks. Will share my findings if any here