私はAndroid向けのプログラミングアプリの初心者です。achartengine でリアルタイム データをプロットしようとしています。問題は、しばらくするとアプリケーションがクラッシュすることです。問題は再描画方法であり、グラフに新しいデータを追加することは、スレッドの問題であるはずです。スレッドを制御するにはどうすればよいですか、またはグラフを描画するためのより良い解決策を見つけるにはどうすればよいですか? あなたが私を助けることができれば、それは素晴らしいことです.
public class Plot2Activity extends Activity {
private static GraphicalView view;
private LineGraph line = new LineGraph();
private static Thread thread;
private static int x=0;
private static boolean mrepainted = false;
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
view = line.getView(this);
setContentView(view);
thread = new Thread() {
public void run() {
/*for (int i = 0; i < 1000; i++) {
try {
Thread.sleep(50);
} catch (InterruptedException e) {
e.printStackTrace();
}
Point p = MockData.getDataFromReceiver(x++); // new data
line.addNewPoints(p); // add it to our graph
view.repaint();
}*/
while (true) {
try {
Thread.sleep(50);
} catch (InterruptedException e) {
e.printStackTrace();
}
Point p = MockData.getDataFromReceiver(x++); // new data
line.addNewPoints(p); // add it to our graph
// Log.e("PLOT", "PLOT:"+x); view.repaint();
}
}
};
thread.start();
}
@Override
protected void onStart() {
super.onStart();
//view = line.getView(this);
//setContentView(view);
}
@Override
protected void onResume() {
super.onResume();
}
}
ログキャット:
10-08 13:23:22.012: E/AndroidRuntime(9267): 致命的な例外: メイン 10-08 13:23:22.012: E/AndroidRuntime(9267): java.util.ConcurrentModificationException 10-08 13:23:22.012: E/AndroidRuntime(9267): java.util.TreeMap$MapIterator.stepForward(TreeMap.java:883) 10-08 13:23:22.012: E/AndroidRuntime(9267): java.util.TreeMap$BoundedMap$BoundedIterator で.stepForward(TreeMap.java:1485) 10-08 13:23:22.012: E/AndroidRuntime(9267): java.util.TreeMap$BoundedMap$BoundedEntrySet$1.next(TreeMap.java:1513) 10-08 13: 23:22.012: E/AndroidRuntime(9267): java.util.TreeMap$BoundedMap$BoundedEntrySet$1.next(TreeMap.java:1511) 10-08 13:23:22.012: E/AndroidRuntime(9267): org. achartengine.chart.XYChart.draw(XYChart.java:250) 10-08 13:23:22.012: E/AndroidRuntime(9267): org.achartengine.GraphicalView で。onDraw(GraphicalView.java:166) 10-08 13:23:22.012: E/AndroidRuntime(9267): android.view.View.draw(View.java:13458) 10-08 13:23:22.012: E/ AndroidRuntime(9267): android.view.View.draw(View.java:13342) 10-08 13:23:22.012: E/AndroidRuntime(9267): android.view.ViewGroup.drawChild(ViewGroup.java:2929) ) 10-08 13:23:22.012: E/AndroidRuntime(9267): android.view.ViewGroup.dispatchDraw(ViewGroup.java:2799) で 10-08 13:23:22.012: E/AndroidRuntime(9267): Android で.view.View.draw(View.java:13340) 10-08 13:23:22.012: E/AndroidRuntime(9267): android.view.ViewGroup.drawChild(ViewGroup.java:2929) 10-08 13:23 :22.012: E/AndroidRuntime(9267): android.view.ViewGroup.dispatchDraw(ViewGroup.java:2799) 10-08 13:23:22.012: E/AndroidRuntime(9267): android.view.View.draw( View.java:13340) 10-08 13:23:22。012: E/AndroidRuntime(9267): android.view.ViewGroup.drawChild(ViewGroup.java:2929) 10-08 13:23:22.012: E/AndroidRuntime(9267): android.view.ViewGroup.dispatchDraw(ViewGroup) .java:2799) 10-08 13:23:22.012: E/AndroidRuntime(9267): android.view.View.draw(View.java:13461) 10-08 13:23:22.012: E/AndroidRuntime(9267) ): android.widget.FrameLayout.draw(FrameLayout.java:467) 10-08 13:23:22.012: E/AndroidRuntime(9267): com.android.internal.policy.impl.PhoneWindow$DecorView.draw( PhoneWindow.java:2183) 10-08 13:23:22.012: E/AndroidRuntime(9267): android.view.ViewRootImpl.drawSoftware(ViewRootImpl.java:2256) 10-08 13:23:22.012: E/AndroidRuntime( 9267): android.view.ViewRootImpl.draw(ViewRootImpl.java:2151) 10-08 13:23:22.012: E/AndroidRuntime(9267): android.view.ViewRootImpl で。performDraw(ViewRootImpl.java:2019) 10-08 13:23:22.012: E/AndroidRuntime(9267): android.view.ViewRootImpl.performTraversals(ViewRootImpl.java:1830) 10-08 13:23:22.012: E/ AndroidRuntime(9267): android.view.ViewRootImpl.doTraversal(ViewRootImpl.java:998) 10-08 13:23:22.012: E/AndroidRuntime(9267): android.view.ViewRootImpl$TraversalRunnable.run(ViewRootImpl.java で:4212) 10-08 13:23:22.012: E/AndroidRuntime(9267): android.view.Choreographer$CallbackRecord.run(Choreographer.java:725) 10-08 13:23:22.012: E/AndroidRuntime(9267) ): android.view.Choreographer.doCallbacks(Choreographer.java:555) 10-08 13:23:22.012: E/AndroidRuntime(9267): android.view.Choreographer.doFrame(Choreographer.java:525) 10- 08 13:23:22.012: E/AndroidRuntime(9267): android.view で。Choreographer$FrameDisplayEventReceiver.run(Choreographer.java:711) 10-08 13:23:22.012: E/AndroidRuntime(9267): android.os.Handler.handleCallback(Handler.java:615) 10-08 13:23: 22.012: E/AndroidRuntime(9267): android.os.Handler.dispatchMessage(Handler.java:92) 10-08 13:23:22.012: E/AndroidRuntime(9267): android.os.Looper.loop(ルーパー) .java:137) 10-08 13:23:22.012: E/AndroidRuntime(9267): android.app.ActivityThread.main(ActivityThread.java:4745) 10-08 13:23:22.012: E/AndroidRuntime(9267) ): java.lang.reflect.Method.invokeNative(Native Method) 10-08 13:23:22.012: E/AndroidRuntime(9267): java.lang.reflect.Method.invoke(Method.java:511) 10 -08 13:23:22.012: E/AndroidRuntime (9267): com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run (ZygoteInit.java:786) 10-08 13:23:22.012:E/AndroidRuntime (9267): com.android.internal.os.ZygoteInit.main (ZygoteInit.java:553) 10-08 13:23:22.012: E/AndroidRuntime (9267): dalvik.system.NativeStart.main で(ネイティブメソッド)