jjoe64 / GraphView

Android Graph Library for creating zoomable and scrollable line and bar graphs.
https://github.com/jjoe64/GraphView/wiki
Other
2.75k stars 811 forks source link

App Crash #683

Open valerio-arcobelli opened 2 years ago

valerio-arcobelli commented 2 years ago

Hello everyone,

I am using this library for plotting real-time coming data. I clean the graph each 2000 samples reiceved in order to not stress the visualization capability. I also activate Log.v in some parts of my code. At some point in a randomly way I got this error from my Log:

V/Plot 1: OK V/Plot 3: OK V/Plot 2: OK V/Plot 1: OK V/Plot 3: OK V/Plot 2: OK D/AndroidRuntime: Shutting down VM E/AndroidRuntime: FATAL EXCEPTION: main Process: com.example.myapplication.exo_app, PID: 2918 java.lang.NullPointerException: Attempt to invoke interface method 'double com.jjoe64.graphview.series.DataPointInterface.getX()' on a null object reference at com.jjoe64.graphview.series.BaseSeries.getLowestValueX(BaseSeries.java:125) at com.jjoe64.graphview.Viewport.calcCompleteRange(Viewport.java:741) at com.jjoe64.graphview.GraphView.onDataChanged(GraphView.java:283) at com.jjoe64.graphview.Viewport.scrollToEnd(Viewport.java:1180) at com.jjoe64.graphview.series.BaseSeries.appendData(BaseSeries.java:484) at com.jjoe64.graphview.series.LineGraphSeries.appendData(LineGraphSeries.java:677) at com.jjoe64.graphview.series.BaseSeries.appendData(BaseSeries.java:502) at com.example.myapplication.exo_app.MainActivity$Thread2$1.run(MainActivity.java:418) at android.os.Handler.handleCallback(Handler.java:883) at android.os.Handler.dispatchMessage(Handler.java:100) at android.os.Looper.loop(Looper.java:224) at android.app.ActivityThread.main(ActivityThread.java:7560) 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:950) I/Process: Sending signal. PID: 2918 SIG: 9

Based in my code in MainActivity.java:

if (data[7]%plot_freq==0) { series.appendData(new DataPoint(x, pitch_1),true,500); Log.v("Plot 1","OK"); } if (data_2[7]%plot_freq==0) { series_2.appendData(new DataPoint(x, pitch_2),true,500); Log.v("Plot 2","OK"); } if (data_3[7]%plot_freq==0) { series_3.appendData(new DataPoint(x, pitch_3),true,500); Log.v("Plot 3","OK"); }

It means that I got error before appending 3rd series. Has anyone has an idea?

Thanks,