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.53k stars 9.01k forks source link

Basic 2, Multiple .... Bar Chart crashes (Example project) #4801

Open Stephan-Enoro opened 4 years ago

Stephan-Enoro commented 4 years ago

Hi I just downloaded MPAndroid Charts for evaluation. The library looks very good. I basically need bar chart to replace Shinobi charts.

Almost all bar chart crashes. Other type of chars work like a charm. It is also quite difficult to debug due application termination in while in a break point. My misstake is that a background thread cause this problem.

It seems always crash on 'int java.util.List.size()' on a null object reference in the render class.

Any idea how to build/run the example would be very welcome.

Thanks in advanced.

Device (please complete the following information):

Stack output:

E/AndroidRuntime: FATAL EXCEPTION: main Process: com.xxmassdeveloper.mpchartexample, PID: 26298 java.lang.NullPointerException: Attempt to invoke interface method 'int java.util.List.size()' on a null object reference at com.github.mikephil.charting.renderer.BarChartRenderer.drawDataSet(BarChartRenderer.java:147) at com.github.mikephil.charting.renderer.BarChartRenderer.drawData(BarChartRenderer.java:81) at com.github.mikephil.charting.charts.BarLineChartBase.onDraw(BarLineChartBase.java:242) at android.view.View.draw(View.java:21605) at android.view.View.updateDisplayListIfDirty(View.java:20470) at android.view.View.draw(View.java:21337) at android.view.ViewGroup.drawChild(ViewGroup.java:4446) at android.view.ViewGroup.dispatchDraw(ViewGroup.java:4205) at android.view.View.updateDisplayListIfDirty(View.java:20461) at android.view.View.draw(View.java:21337) at android.view.ViewGroup.drawChild(ViewGroup.java:4446) at android.view.ViewGroup.dispatchDraw(ViewGroup.java:4205) at android.view.View.updateDisplayListIfDirty(View.java:20461) at android.view.View.draw(View.java:21337) at android.view.ViewGroup.drawChild(ViewGroup.java:4446) at android.view.ViewGroup.dispatchDraw(ViewGroup.java:4205) at android.view.View.updateDisplayListIfDirty(View.java:20461) at android.view.View.draw(View.java:21337) at android.view.ViewGroup.drawChild(ViewGroup.java:4446) at android.view.ViewGroup.dispatchDraw(ViewGroup.java:4205) at android.view.View.updateDisplayListIfDirty(View.java:20461) at android.view.View.draw(View.java:21337) at android.view.ViewGroup.drawChild(ViewGroup.java:4446) at android.view.ViewGroup.dispatchDraw(ViewGroup.java:4205) at android.view.View.updateDisplayListIfDirty(View.java:20461) at android.view.View.draw(View.java:21337) at android.view.ViewGroup.drawChild(ViewGroup.java:4446) at android.view.ViewGroup.dispatchDraw(ViewGroup.java:4205) at android.view.View.draw(View.java:21608) at com.android.internal.policy.DecorView.draw(DecorView.java:964) at android.view.View.updateDisplayListIfDirty(View.java:20470) at android.view.ThreadedRenderer.updateViewTreeDisplayList(ThreadedRenderer.java:584) at android.view.ThreadedRenderer.updateRootDisplayList(ThreadedRenderer.java:590) at android.view.ThreadedRenderer.draw(ThreadedRenderer.java:668) at android.view.ViewRootImpl.draw(ViewRootImpl.java:3835) at android.view.ViewRootImpl.performDraw(ViewRootImpl.java:3643) at android.view.ViewRootImpl.performTraversals(ViewRootImpl.java:2949) at android.view.ViewRootImpl.doTraversal(ViewRootImpl.java:1852) at android.view.ViewRootImpl$TraversalRunnable.run(ViewRootImpl.java:8084) at android.view.Choreographer$CallbackRecord.run(Choreographer.java:1057) at android.view.Choreographer.doCallbacks(Choreographer.java:875) at android.view.Choreographer.doFrame(Choreographer.java:776) at android.view.Choreographer$FrameDisplayEventReceiver.run(Choreographer.java:1042) at android.os.Handler.handleCallback(Handler.java:888) at android.os.Handler.dispatchMessage(Handler.java:100) at android.os.Looper.loop(Looper.java:213) at android.app.ActivityThread.main(ActivityThread.java:8147) at java.lang.reflect.Method.invoke(Native Method) at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:513) at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:1101)

Chakib-Temal commented 4 years ago

did you use BarData ? to combine multiple BarDataSet

Stephan-Enoro commented 4 years ago

I did not change the example. Clone, build and execute. All bar samples crashed with one exception: Basic
All scrolling charts also crashed. Line charts, Pie chart, Pie charts, Even More Line charts work like a charm.

I guess there is something very silly that make this crash. null datasource could be the case. Otherwise the code and the UI looks very good.

Chakib-Temal commented 4 years ago

you don't need to clone and build

create a new project and take only a copy of an exemple and put it in your Activity

for exemple : i already used the multiple Bar, use this example

https://github.com/PhilJay/MPAndroidChart/blob/v2.2.2/MPChartExample/src/com/xxmassdeveloper/mpchartexample/BarChartActivityMultiDataset.java

take only the necessary (copy - past) , and it should be run without any problems

Chakib-Temal commented 4 years ago

be carfull for the version MpChartAndroid i use the 2.2.2 ,

if you use another version , change the tag branche on gitHub Mpchart page home and choose your version, so you can after search the example according your version

Stephan-Enoro commented 4 years ago

Thanks @Chakib-Temal . Excellent. I will follow your example. BTW: When I debug the MPAC example project, i.e add a breakpoint, wait for 5-8 seconds and the app terminates. Restarted Android Studio. Same thing. Very strange. I guess your example works better. Thanks again.