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

IndexOutOfBoundsException #5107

Open rangerzhou opened 3 years ago

rangerzhou commented 3 years ago

Summary

Expected Behavior

Possible Solution

Device (please complete the following information):

Additional Context

ADD A REWARD using Speed to SOLVE this issue QUICKLY and SUPPORT this project.

2021-03-05 16:31:19.625 32631-32631/com.aptiv.tempcode E/AndroidRuntime: FATAL EXCEPTION: main
    Process: com.aptiv.tempcode, PID: 32631
    java.lang.IndexOutOfBoundsException: Index: 0, Size: 1
        at java.util.ArrayList.get(ArrayList.java:437)
        at com.github.mikephil.charting.renderer.LegendRenderer.renderLegend(LegendRenderer.java:377)
        at com.github.mikephil.charting.charts.BarLineChartBase.onDraw(BarLineChartBase.java:281)
        at android.view.View.draw(View.java:21564)
        at android.view.View.updateDisplayListIfDirty(View.java:20433)
        at android.view.ViewGroup.recreateChildDisplayList(ViewGroup.java:4401)
        at android.view.ViewGroup.dispatchGetDisplayList(ViewGroup.java:4374)
        at android.view.View.updateDisplayListIfDirty(View.java:20393)
        at android.view.ViewGroup.recreateChildDisplayList(ViewGroup.java:4401)
        at android.view.ViewGroup.dispatchGetDisplayList(ViewGroup.java:4374)
        at android.view.View.updateDisplayListIfDirty(View.java:20393)
        at android.view.ViewGroup.recreateChildDisplayList(ViewGroup.java:4401)
        at android.view.ViewGroup.dispatchGetDisplayList(ViewGroup.java:4374)
        at android.view.View.updateDisplayListIfDirty(View.java:20393)
        at android.view.ViewGroup.recreateChildDisplayList(ViewGroup.java:4401)
        at android.view.ViewGroup.dispatchGetDisplayList(ViewGroup.java:4374)
        at android.view.View.updateDisplayListIfDirty(View.java:20393)
        at android.view.ViewGroup.recreateChildDisplayList(ViewGroup.java:4401)
        at android.view.ViewGroup.dispatchGetDisplayList(ViewGroup.java:4374)
        at android.view.View.updateDisplayListIfDirty(View.java:20393)
        at android.view.ViewGroup.recreateChildDisplayList(ViewGroup.java:4401)
        at android.view.ViewGroup.dispatchGetDisplayList(ViewGroup.java:4374)
        at android.view.View.updateDisplayListIfDirty(View.java:20393)
        at android.view.ViewGroup.recreateChildDisplayList(ViewGroup.java:4401)
        at android.view.ViewGroup.dispatchGetDisplayList(ViewGroup.java:4374)
        at android.view.View.updateDisplayListIfDirty(View.java:20393)
        at android.view.ViewGroup.recreateChildDisplayList(ViewGroup.java:4401)
        at android.view.ViewGroup.dispatchGetDisplayList(ViewGroup.java:4374)
        at android.view.View.updateDisplayListIfDirty(View.java:20393)
        at android.view.ViewGroup.recreateChildDisplayList(ViewGroup.java:4401)
        at android.view.ViewGroup.dispatchGetDisplayList(ViewGroup.java:4374)
        at android.view.View.updateDisplayListIfDirty(View.java:20393)
        at android.view.ThreadedRenderer.updateViewTreeDisplayList(ThreadedRenderer.java:575)
        at android.view.ThreadedRenderer.updateRootDisplayList(ThreadedRenderer.java:581)
        at android.view.ThreadedRenderer.draw(ThreadedRenderer.java:654)
        at android.view.ViewRootImpl.draw(ViewRootImpl.java:3732)
        at android.view.ViewRootImpl.performDraw(ViewRootImpl.java:3527)
        at android.view.ViewRootImpl.performTraversals(ViewRootImpl.java:2864)
        at android.view.ViewRootImpl.doTraversal(ViewRootImpl.java:1817)
        at android.view.ViewRootImpl$TraversalRunnable.run(ViewRootImpl.java:7779)
        at android.view.Choreographer$CallbackRecord.run(Choreographer.java:1031)
        at android.view.Choreographer.doCallbacks(Choreographer.java:854)
        at android.view.Choreographer.doFrame(Choreographer.java:789)
        at android.view.Choreographer$FrameDisplayEventReceiver.run(Choreographer.java:1016)
        at android.os.Handler.handleCallback(Handler.java:914)
        at android.os.Handler.dispatchMessage(Handler.java:100)
        at android.os.Looper.loop(Looper.java:227)
        at android.app.ActivityThread.main(ActivityThread.java:7582)
        at java.lang.reflect.Method.invoke(Native Method)
        at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:539)
        at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:953)
2021-03-05 16:31:19.655 32631-32631/com.aptiv.tempcode I/Process: Sending signal. PID: 32631 SIG: 9
zengweitao commented 3 years ago

我也遇到了这个问题,请问有解决办法吗?

rangerzhou commented 3 years ago

我也遇到了这个问题,请问有解决办法吗?

目前没有,看异常是 MPAndroidChart 库的 bug,加 try catch 无法捕获,还有其他几个异常也差不多,但是无人解决,你可以尝试一下图表相关操作放在 runOnUiThread() 中,似乎会好一些:

                    requireActivity().runOnUiThread(new Runnable() {
                        @Override
                        public void run() {
                            updateChart(ubdObj);
                        }
                    });
rangerzhou commented 3 years ago

我也遇到了这个问题,请问有解决办法吗?

你名字和我一个同学一样哈哈

zengweitao commented 3 years ago

你同学是哪位?说不定你说的那位同学就是我,哈哈哈,可以加我微信 18738523758

rangerzhou commented 3 years ago

你同学是哪位?说不定你说的那位同学就是我,哈哈哈,可以加我微信 18738523758

郑伟涛,河南的,然后顺便说下这个问题可以解决了,addEntry的时候使用addEntryOrdered就可以了

zengweitao commented 3 years ago

同学,你是哪位,我就是你说的那位,哈哈哈,联系我一下吧