Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
2.1k views
in Technique[技术] by (71.8m points)

google maps - Android 2.1 GoogleMaps ItemizedOverlay ConcurrentModificationException

I cannot figure out the origin of the ConcurrentModificationException. In my activity I'm calling updateMapOverlay(). I'm also calling updateMapOverlay() inside another Thread (a TimerTask) that is invoked on regular intervals. I'm taking the appropriate locks when invoking updateMapOverlay() from both the threads. Is this problem being caused because I'm invoking updateMapOverlay from inside a non-UI thread (i.e., TimerTask). Has anyone else faced a similar issue ?

private void updateMapOverlay() {

    this.itemizedOverlay.refreshItems(createOverlayItemsList());
    List<Overlay> overlays = mapView.getOverlays();
    overlays.clear();
    overlays.add(cotItemizedOverlay);
            this.mapview.invalidate();

}

Thanks.

Exception:

W/dalvikvm(10641): threadid=3: thread exiting with uncaught exception (group=0x4001b180)
E/AndroidRuntime(10641): Uncaught handler: thread main exiting due to uncaught exception
E/AndroidRuntime(10641): java.util.ConcurrentModificationException
E/AndroidRuntime(10641):    at java.util.AbstractList$SimpleListIterator.next(AbstractList.java:64)
E/AndroidRuntime(10641):    at com.google.android.maps.OverlayBundle.draw(OverlayBundle.java:41)
E/AndroidRuntime(10641):    at com.google.android.maps.MapView.onDraw(MapView.java:494)
E/AndroidRuntime(10641):    at android.view.View.draw(View.java:6535)
E/AndroidRuntime(10641):    at android.view.ViewGroup.drawChild(ViewGroup.java:1531)
E/AndroidRuntime(10641):    at android.view.ViewGroup.dispatchDraw(ViewGroup.java:1258)
E/AndroidRuntime(10641):    at android.view.ViewGroup.drawChild(ViewGroup.java:1529)
E/AndroidRuntime(10641):    at android.view.ViewGroup.dispatchDraw(ViewGroup.java:1258)
E/AndroidRuntime(10641):    at android.view.View.draw(View.java:6538)
E/AndroidRuntime(10641):    at android.widget.FrameLayout.draw(FrameLayout.java:352)
E/AndroidRuntime(10641):    at android.view.ViewGroup.drawChild(ViewGroup.java:1531)
E/AndroidRuntime(10641):    at android.view.ViewGroup.dispatchDraw(ViewGroup.java:1258)
E/AndroidRuntime(10641):    at android.view.ViewGroup.drawChild(ViewGroup.java:1529)
E/AndroidRuntime(10641):    at android.view.ViewGroup.dispatchDraw(ViewGroup.java:1258)
E/AndroidRuntime(10641):    at android.view.View.draw(View.java:6538)
E/AndroidRuntime(10641):    at android.widget.FrameLayout.draw(FrameLayout.java:352)
E/AndroidRuntime(10641):    at com.android.internal.policy.impl.PhoneWindow$DecorView.draw(PhoneWindow.java:1830)
E/AndroidRuntime(10641):    at android.view.ViewRoot.draw(ViewRoot.java:1349)
E/AndroidRuntime(10641):    at android.view.ViewRoot.performTraversals(ViewRoot.java:1114)
E/AndroidRuntime(10641):    at android.view.ViewRoot.handleMessage(ViewRoot.java:1633)
E/AndroidRuntime(10641):    at android.os.Handler.dispatchMessage(Handler.java:99)
E/AndroidRuntime(10641):    at android.os.Looper.loop(Looper.java:123)
E/AndroidRuntime(10641):    at android.app.ActivityThread.main(ActivityThread.java:4363)
E/AndroidRuntime(10641):    at java.lang.reflect.Method.invokeNative(Native Method)
E/AndroidRuntime(10641):    at java.lang.reflect.Method.invoke(Method.java:521)
E/AndroidRuntime(10641):    at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:860)
E/AndroidRuntime(10641):    at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:618)
E/AndroidRuntime(10641):    at dalvik.system.NativeStart.main(Native Method)
I/Process (   95): Sending signal. PID: 10641 SIG: 3
See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

Is this problem being caused because I'm invoking updateMapOverlay from inside a non-UI thread

Yes.

I'm also calling updateMapOverlay() inside another Thread (a TimerTask) that is invoked on regular intervals.

Why are you removing and adding an overlay constantly? Just update the overlay and invalidate. See here for an example of updating an overlay asynchronously.


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...