I am writing a code in which the graph must be continiously updated by repeatedly calling the aSyncTask. but to ensure thet the graph doesnot get too compressed, I plan to remove/ delete the oldest entry beyond a point. Presently my code is as follows:
int counter = 0;
private class UpdateLineGraphAsync extends AsyncTask<Void, Void, Void> {
@Override
protected Void doInBackground(Void... params) {
// add the next series value
series.add(counter, Math.sin((double) counter / 100));
counter += 20;
if (counter > 500)
series.remove(0);
return null;
}
@Override
protected void onPostExecute(Void result) {
// TODO Auto-generated method stub
super.onPostExecute(result);
((GraphicalView) lineGraph).repaint(); // repaints the graph!
}
}
But this code keeps giving me a null point exception when i call remove(0); Can anyone explain how the function XYSeries.remove(index) works? I read somewhere that it is a LIFO structure. is this true? How to correct this error? even a single call of the remove function gives an error.
The error codes are:
07-03 17:27:36.080: E/AndroidRuntime(1229): FATAL EXCEPTION: AsyncTask #2
07-03 17:27:36.080: E/AndroidRuntime(1229): java.lang.RuntimeException: An error occured while executing doInBackground()
07-03 17:27:36.080: E/AndroidRuntime(1229): at android.os.AsyncTask$3.done(AsyncTask.java:200)
07-03 17:27:36.080: E/AndroidRuntime(1229): at java.util.concurrent.FutureTask$Sync.innerSetException(FutureTask.java:274)
07-03 17:27:36.080: E/AndroidRuntime(1229): at java.util.concurrent.FutureTask.setException(FutureTask.java:125)
07-03 17:27:36.080: E/AndroidRuntime(1229): at java.util.concurrent.FutureTask$Sync.innerRun(FutureTask.java:308)
07-03 17:27:36.080: E/AndroidRuntime(1229): at java.util.concurrent.FutureTask.run(FutureTask.java:138)
07-03 17:27:36.080: E/AndroidRuntime(1229): at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1088)
07-03 17:27:36.080: E/AndroidRuntime(1229): at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:581)
07-03 17:27:36.080: E/AndroidRuntime(1229): at java.lang.Thread.run(Thread.java:1027)
07-03 17:27:36.080: E/AndroidRuntime(1229): Caused by: java.lang.NullPointerException
07-03 17:27:36.080: E/AndroidRuntime(1229): at org.achartengine.model.XYSeries.getY(XYSeries.java:169)
07-03 17:27:36.080: E/AndroidRuntime(1229): at org.achartengine.model.XYSeries.initRange(XYSeries.java:83)
07-03 17:27:36.080: E/AndroidRuntime(1229): at org.achartengine.model.XYSeries.remove(XYSeries.java:140)
07-03 17:27:36.080: E/AndroidRuntime(1229): at com.clearbridgevitalsigns.cardioleaf.LiveView$UpdateLineGraphAsync.doInBackground(LiveView.java:121)
07-03 17:27:36.080: E/AndroidRuntime(1229): at com.clearbridgevitalsigns.cardioleaf.LiveView$UpdateLineGraphAsync.doInBackground(LiveView.java:1)
07-03 17:27:36.080: E/AndroidRuntime(1229): at android.os.AsyncTask$2.call(AsyncTask.java:185)
07-03 17:27:36.080: E/AndroidRuntime(1229): at java.util.concurrent.FutureTask$Sync.innerRun(FutureTask.java:306)
07-03 17:27:36.080: E/AndroidRuntime(1229): ... 4 more