java.util.ConcurrentModificationException?

时间:2011-06-09 14:05:15

标签: android google-maps

请指导我在这做什么错? 任何帮助将不胜感激。

private void LoopThroughEachATMToDisplayOnMap()
           {


               Drawable drawable = null;

                for (int i = 0; i < atm.getAtmList().size(); i++) {

                    if(breakFlag)
                        break;

                    drawable = getAppropriatePin(i);
                    if(drawable == null) 
                    drawable = getResources().getDrawable(R.drawable.marker);
                    itemizedOverlay = new MyItemizedOverlay(drawable, mapView);

                    ATM a = atm.getAtmList().get(i);
                    if (a != null) {
                        int[] coordinates = getIntCoordinates(a
                                .getCoordinates());
                        if (coordinates != null) {
                            GeoPoint point = new GeoPoint(coordinates[0],
                                    coordinates[1]);
                            OverlayItem overlayItem = new OverlayItem(
                                    point, a.getBankName(), a.getAddress()
                                            + "@@" + a.getPhone() + "@@"
                                            + a.getWebAddress() + "@@"
                                            + a.getCoordinates());
                            itemizedOverlay.addOverlay(overlayItem);
                            System.out
                                    .println("coordinates-------------------------"
                                            + i + " "
                                            + coordinates[0]
                                            + ","
                                            + coordinates[1]);
                        }

                    }
                    if(mapOverlays == null)
                        mapOverlays = mapView.getOverlays();

                    mapOverlays.add(itemizedOverlay);
                }
                System.out.println("atms maps injection complete--------------------------------");

           }    

    06-09 18:41:12.019: ERROR/AndroidRuntime(13973): Uncaught handler: thread main exiting due to uncaught exception
    06-09 18:41:12.149: ERROR/AndroidRuntime(13973): java.util.ConcurrentModificationException
    06-09 18:41:12.149: ERROR/AndroidRuntime(13973):     at java.util.AbstractList$SimpleListIterator.next(AbstractList.java:64)
    06-09 18:41:12.149: ERROR/AndroidRuntime(13973):     at com.google.android.maps.OverlayBundle.draw(OverlayBundle.java:44)
    06-09 18:41:12.149: ERROR/AndroidRuntime(13973):     at com.google.android.maps.MapView.onDraw(MapView.java:494)
    06-09 18:41:12.149: ERROR/AndroidRuntime(13973):     at android.view.View.draw(View.java:6535)
    06-09 18:41:12.149: ERROR/AndroidRuntime(13973):     at android.view.ViewGroup.drawChild(ViewGroup.java:1585)
    06-09 18:41:12.149: ERROR/AndroidRuntime(13973):     at android.view.ViewGroup.dispatchDraw(ViewGroup.java:1312)
    06-09 18:41:12.149: ERROR/AndroidRuntime(13973):     at android.view.View.draw(View.java:6538)
    06-09 18:41:12.149: ERROR/AndroidRuntime(13973):     at android.view.ViewGroup.drawChild(ViewGroup.java:1585)
    06-09 18:41:12.149: ERROR/AndroidRuntime(13973):     at android.view.ViewGroup.dispatchDraw(ViewGroup.java:1312)
    06-09 18:41:12.149: ERROR/AndroidRuntime(13973):     at android.view.View.draw(View.java:6538)
    06-09 18:41:12.149: ERROR/AndroidRuntime(13973):     at android.widget.FrameLayout.draw(FrameLayout.java:352)
    06-09 18:41:12.149: ERROR/AndroidRuntime(13973):     at android.view.ViewGroup.drawChild(ViewGroup.java:1585)
    06-09 18:41:12.149: ERROR/AndroidRuntime(13973):     at android.view.ViewGroup.dispatchDraw(ViewGroup.java:1312)
    06-09 18:41:12.149: ERROR/AndroidRuntime(13973):     at android.view.View.draw(View.java:6538)
    06-09 18:41:12.149: ERROR/AndroidRuntime(13973):     at android.widget.FrameLayout.draw(FrameLayout.java:352)
    06-09 18:41:12.149: ERROR/AndroidRuntime(13973):     at com.android.internal.policy.impl.PhoneWindow$DecorView.draw(PhoneWindow.java:1866)
    06-09 18:41:12.149: ERROR/AndroidRuntime(13973):     at android.view.ViewRoot.draw(ViewRoot.java:1364)
    06-09 18:41:12.149: ERROR/AndroidRuntime(13973):     at android.view.ViewRoot.performTraversals(ViewRoot.java:1118)
    06-09 18:41:12.149: ERROR/AndroidRuntime(13973):     at android.view.ViewRoot.handleMessage(ViewRoot.java:1650)
    06-09 18:41:12.149: ERROR/AndroidRuntime(13973):     at android.os.Handler.dispatchMessage(Handler.java:99)
    06-09 18:41:12.149: ERROR/AndroidRuntime(13973):     at android.os.Looper.loop(Looper.java:123)
    06-09 18:41:12.149: ERROR/AndroidRuntime(13973):     at android.app.ActivityThread.main(ActivityThread.java:4595)
    06-09 18:41:12.149: ERROR/AndroidRuntime(13973):     at java.lang.reflect.Method.invokeNative(Native Method)
    06-09 18:41:12.149: ERROR/AndroidRuntime(13973):     at java.lang.reflect.Method.invoke(Method.java:521)
    06-09 18:41:12.149: ERROR/AndroidRuntime(13973):     at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:860)
    06-09 18:41:12.149: ERROR/AndroidRuntime(13973):     at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:618)
    06-09 18:41:12.149: ERROR/AndroidRuntime(13973):     at dalvik.system.NativeStart.main(Native Method)

1 个答案:

答案 0 :(得分:5)

我得到了自己的答案。

实际上是mapOverlays.add(itemizedOverlay);需要你去运行。

所以这不是ui线程,这就是它引起错误的原因。

我刚刚在uithread中运行了该功能,这解决了我的问题。