gpt4 book ai didi

安卓 2.1 GoogleMaps ItemizedOverlay ConcurrentModificationException

转载 作者:行者123 更新时间:2023-11-29 14:42:44 24 4
gpt4 key购买 nike

我无法弄清楚 ConcurrentModificationException 的来源。在我的 activity 中,我正在调用 updateMapOverlay()。我还在定期调用的另一个线程(TimerTask)中调用 updateMapOverlay()。从两个线程调用 updateMapOverlay() 时,我采用了适当的锁定。这个问题是因为我从非 UI 线程(即 TimerTask)调用 updateMapOverlay 引起的吗?还有其他人遇到过类似的问题吗?


private void updateMapOverlay() {



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

}

谢谢。

异常:

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

最佳答案

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

是的。

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

为什么要不断地删除和添加叠加层?只需更新覆盖并使其失效。参见 here for an example异步更新叠加层。

关于安卓 2.1 GoogleMaps ItemizedOverlay ConcurrentModificationException,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/2870743/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com