我正在开发一个 android 应用程序,我从蓝牙接收 eeg 信号并使用 achartengine 实时显示它。我使用异步任务来显示图表并更新它。但是,我每次都得到 ConcurrentModificationException 。该图会显示一段时间,然后给出该错误。下面是我的代码。
mstart.setOnClickListener(new OnClickListener() {
@Override
public void onClick(View arg0)
{
// TODO Auto-generated method stub
// tv.setText("Fetal Heart rate loading..");
// index = 0;
flag = true;
if(fhr_alg!=null)
fhr_alg = null;
fhr_alg = new AddStringTask();
algo_done = false;
/*curr = 5;
counter = 0;*/
//// a1.setFlag(true);
//a1.setMax(0);
Thread tt = new Thread()
{
public void run()
{
try{
sleep(600);
} catch (InterruptedException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}finally{
fhr_alg.execute();
}
}
};tt.start();
if (view_eeg1== null) {
LinearLayout layout_eeg1 = (LinearLayout) findViewById(R.id.layout2);
view_eeg1= ChartFactory.getLineChartView(BluetoothConnect.this, eeg1, renderer_eeg1);
// layout_eeg1.
layout_eeg1.addView(view_eeg1);
} else {
view_eeg1.repaint();}
// w1.loadUrl("javascript:callJS()");
mstart.setEnabled(false);
}
});
class AddStringTask extends android.os.AsyncTask<Void, Integer, Integer> {
@Override
protected void onPostExecute(Integer result) {
// TODO Auto-generated method stub
super.onPostExecute(result);
algo_done=true;
//Toast.makeText(Html.this, "Done Algo !", Toast.LENGTH_SHORT).show();
}
@SuppressLint("UseValueOf")
@Override
protected Integer doInBackground(Void... unused) {
try {
for(int r=0;r<=5000;r++){
//Thread.sleep(300);
series1.add(r,data[r]);
// w2.loadUrl("javascript:count(\""+data[r]+"\")");
if(r<=250){
renderer_eeg1.setXAxisMax(250);
}
else if(r>250){
double maxX = series1.getMaxX();
double minX = maxX - 250;
renderer_eeg1.setXAxisMin(minX);
renderer_eeg1.setXAxisMax(maxX);
}
view_eeg1.repaint();
publishProgress((int)data[r]);
SystemClock.sleep(600);
}
} catch (Exception e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
return (0);
}
@Override
protected void onProgressUpdate(Integer ... value) {
int fhr=value[0];
view_eeg1.repaint();
w2.loadUrl("javascript:count(\""+fhr+"\")");
//a1.setfhr(curr, fhr);
//curr++;
}
}
谁能告诉我为什么会出现这个错误以及如何解决它。谢谢