問題の概要は次のとおりです。
バスの位置を追跡する BusLocator というクラスがあります。現在、テキストファイルから入力を取得しています。
プログラムは問題なく開始し、バスが画面の端に到達したとき、または何か他のものを見ようとするとランダムに停止します。
ここに私のエラーがあります:
12-10 08:28:43.014: E/AndroidRuntime(15257): FATAL EXCEPTION: main
12-10 08:28:43.014: E/AndroidRuntime(15257): java.util.ConcurrentModificationException
12-10 08:28:43.014: E/AndroidRuntime(15257): at java.util.ArrayList$ArrayListIterator.next(ArrayList.java:569)
12-10 08:28:43.014: E/AndroidRuntime(15257): at com.google.android.maps.OverlayBundle.draw(OverlayBundle.java:41)
12-10 08:28:43.014: E/AndroidRuntime(15257): at com.google.android.maps.MapView.onDraw(MapView.java:532)
12-10 08:28:43.014: E/AndroidRuntime(15257): at android.view.View.draw(View.java:13707)
12-10 08:28:43.014: E/AndroidRuntime(15257): at android.view.View.draw(View.java:13591)
12-10 08:28:43.014: E/AndroidRuntime(15257): at android.view.ViewGroup.drawChild(ViewGroup.java:2928)
12-10 08:28:43.014: E/AndroidRuntime(15257): at android.view.ViewGroup.dispatchDraw(ViewGroup.java:2797)
12-10 08:28:43.014: E/AndroidRuntime(15257): at android.view.View.draw(View.java:13589)
12-10 08:28:43.014: E/AndroidRuntime(15257): at android.view.ViewGroup.drawChild(ViewGroup.java:2928)
12-10 08:28:43.014: E/AndroidRuntime(15257): at android.view.ViewGroup.dispatchDraw(ViewGroup.java:2797)
12-10 08:28:43.014: E/AndroidRuntime(15257): at android.view.View.draw(View.java:13710)
12-10 08:28:43.014: E/AndroidRuntime(15257): at android.widget.FrameLayout.draw(FrameLayout.java:467)
12-10 08:28:43.014: E/AndroidRuntime(15257): at android.view.View.draw(View.java:13591)
12-10 08:28:43.014: E/AndroidRuntime(15257): at android.view.ViewGroup.drawChild(ViewGroup.java:2928)
12-10 08:28:43.014: E/AndroidRuntime(15257): at android.view.ViewGroup.dispatchDraw(ViewGroup.java:2797)
12-10 08:28:43.014: E/AndroidRuntime(15257): at android.view.View.draw(View.java:13589)
12-10 08:28:43.014: E/AndroidRuntime(15257): at android.view.ViewGroup.drawChild(ViewGroup.java:2928)
12-10 08:28:43.014: E/AndroidRuntime(15257): at android.view.ViewGroup.dispatchDraw(ViewGroup.java:2797)
12-10 08:28:43.014: E/AndroidRuntime(15257): at android.view.View.draw(View.java:13710)
12-10 08:28:43.014: E/AndroidRuntime(15257): at android.widget.FrameLayout.draw(FrameLayout.java:467)
12-10 08:28:43.014: E/AndroidRuntime(15257): at com.android.internal.policy.impl.PhoneWindow$DecorView.draw(PhoneWindow.java:2211)
12-10 08:28:43.014: E/AndroidRuntime(15257): at android.view.ViewRootImpl.drawSoftware(ViewRootImpl.java:2281)
12-10 08:28:43.014: E/AndroidRuntime(15257): at android.view.ViewRootImpl.draw(ViewRootImpl.java:2177)
12-10 08:28:43.014: E/AndroidRuntime(15257): at android.view.ViewRootImpl.performDraw(ViewRootImpl.java:2045)
12-10 08:28:43.014: E/AndroidRuntime(15257): at android.view.ViewRootImpl.performTraversals(ViewRootImpl.java:1854)
12-10 08:28:43.014: E/AndroidRuntime(15257): at android.view.ViewRootImpl.doTraversal(ViewRootImpl.java:989)
12-10 08:28:43.014: E/AndroidRuntime(15257): at android.view.ViewRootImpl$TraversalRunnable.run(ViewRootImpl.java:4351)
12-10 08:28:43.014: E/AndroidRuntime(15257): at android.view.Choreographer$CallbackRecord.run(Choreographer.java:749)
12-10 08:28:43.014: E/AndroidRuntime(15257): at android.view.Choreographer.doCallbacks(Choreographer.java:562)
12-10 08:28:43.014: E/AndroidRuntime(15257): at android.view.Choreographer.doFrame(Choreographer.java:532)
12-10 08:28:43.014: E/AndroidRuntime(15257): at android.view.Choreographer$FrameDisplayEventReceiver.run(Choreographer.java:735)
12-10 08:28:43.014: E/AndroidRuntime(15257): at android.os.Handler.handleCallback(Handler.java:725)
12-10 08:28:43.014: E/AndroidRuntime(15257): at android.os.Handler.dispatchMessage(Handler.java:92)
12-10 08:28:43.014: E/AndroidRuntime(15257): at android.os.Looper.loop(Looper.java:137)
12-10 08:28:43.014: E/AndroidRuntime(15257): at android.app.ActivityThread.main(ActivityThread.java:5039)
12-10 08:28:43.014: E/AndroidRuntime(15257): at java.lang.reflect.Method.invokeNative(Native Method)
12-10 08:28:43.014: E/AndroidRuntime(15257): at java.lang.reflect.Method.invoke(Method.java:511)
12-10 08:28:43.014: E/AndroidRuntime(15257): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:793)
12-10 08:28:43.014: E/AndroidRuntime(15257): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:560)
12-10 08:28:43.014: E/AndroidRuntime(15257): at dalvik.system.NativeStart.main(Native Method)
12-10 08:28:45.464: D/dalvikvm(15257): GC_CONCURRENT freed 1479K, 21% free 6387K/7988K, paused 18ms+214ms, total 568ms
12-10 08:28:46.034: I/Process(15257): Sending signal. PID: 15257 SIG: 9
バスの座標を読み取るコードは、次の別のスレッドで実行されます。
class BusThread extends Thread {
private boolean run = true;
private Context context;
BusLocator bus;
public BusThread(Context context,BusLocator bl) {
this.context = context;
this.bus=bl;
}
public void negateRun() {
run = false;
}
public void run() {
try {
AssetManager am = context.getAssets();
InputStream is = am.open("test.txt");
Scanner scan = new Scanner(is);
double longitude;
double latitude;
while (run) {
if (scan.hasNext()) {
latitude = scan.nextDouble();
longitude = scan.nextDouble();
bus.updateBusLoc(longitude,latitude);
//Pause for 2 seconds
Thread.sleep(2000);
}
else
scan.reset();
}
} catch (IOException ioe) {
ioe.printStackTrace();
return;
} catch (InterruptedException ie) {
// TODO Auto-generated catch block
ie.printStackTrace();
return;
}
}
}
そして最後に、理由はわかりませんが、私のエラーがどこから来ているのか:
public void updateBusLoc(double longi,double lati){
if(!onScreen){
onScreen=true;
GeoPoint point = new GeoPoint((int)(lati*1E6),(int)(longi*1E6));
busOverlay.addOverlay(new OverlayItem(point, busTitle, busText));
mapView.getOverlays().add(busOverlay);
}
else
{
GeoPoint point = new GeoPoint((int)(lati*1E6),(int)(longi*1E6));
busOverlay.replaceLastOverlay(new OverlayItem(point,busTitle, busText));
mapView.getOverlays().add(busOverlay);
}
mapView.refreshDrawableState();
}
私はかなり絶望的になっています...これを数時間見ています。どんな助けでも大歓迎です!