0

MapView にいくつかの MapOverlay を追加しようとしていますが、次のエラーが発生します。

java.util.ConcurrentModificationException
at java.util.ArrayList$ArrayListIterator.next(ArrayList.java:569)
at com.google.android.maps.OverlayBundle.draw(OverlayBundle.java:44)
at com.google.android.maps.MapView.onDraw(MapView.java:530)
at android.view.View.draw(View.java:13458)
...
at dalvik.system.NativeStart.main(Native Method)

これは、私の AsyncTask の doInBackground() メソッドです。

Drawable marker = myContext.getResources().getDrawable(
                R.drawable.marker);
        Bitmap bitmap = ((BitmapDrawable) marker).getBitmap();
        Drawable marker_new = new BitmapDrawable(myContext.getResources(),
                Bitmap.createScaledBitmap(
                        bitmap, MainActivity.MARKER_SIZE * 10,
                        MainActivity.MARKER_SIZE * 10, true));

        mapOverlays = map.getOverlays();

        int minLat = Integer.MAX_VALUE;
        int maxLat = Integer.MIN_VALUE;
        int minLon = Integer.MAX_VALUE;
        int maxLon = Integer.MIN_VALUE;
        double fitFactor = 1.1;

        MainActivity.mapListAddress.clear();
        MainActivity.mapListTitle.clear();
        MainActivity.mapListLati.clear();
        MainActivity.mapListLongi.clear();
        MainActivity.parseMaps();

        for (int i = 0; i < MainActivity.mapListAddress.size(); i++) {
            // String pointAddress = MainActivity.mapListAddress.get(i);
            String pointTitel = MainActivity.mapListTitle.get(i);

            MyItemizedOverlay itemizedOverlay = new MyItemizedOverlay(
                    marker_new, map);

            double latitude = MainActivity.mapListLati.get(i) * 1e6;
            double longitude = MainActivity.mapListLongi.get(i) * 1e6;

            Geocoder geocoder;
            List<Address> addresses = null;
            geocoder = new Geocoder(Map.this, Locale.getDefault());
            try {
                addresses = geocoder.getFromLocation(MainActivity.mapListLati.get(i),
                        MainActivity.mapListLongi.get(i), 1);
            } catch (IOException e) {
                e.printStackTrace();
            }
            String address = addresses.get(0).getAddressLine(0);
            String city = addresses.get(0).getAddressLine(1);
            String country = addresses.get(0).getAddressLine(2);
            String pointAddress = address + "\n" + city + "\n" + country;

            GeoPoint p = new GeoPoint((int) latitude, (int) longitude);

            overlayitem = new OverlayItem(p, pointTitel,
                    pointAddress);

            itemizedOverlay.setBalloonBottomOffset(40);
            itemizedOverlay.addOverlay(overlayitem);
            mapOverlays.add(itemizedOverlay);

            int lat = p.getLatitudeE6();
            int lon = p.getLongitudeE6();

            maxLat = Math.max(lat, maxLat);
            minLat = Math.min(lat, minLat);
            maxLon = Math.max(lon, maxLon);
            minLon = Math.min(lon, minLon);

            map.getController().zoomToSpan((int) (Math.abs(maxLat - minLat) * fitFactor),
                    (int) (Math.abs(maxLon - minLon) * fitFactor));
            map.getController().animateTo(new GeoPoint((maxLat + minLat) / 2,
                    (maxLon + minLon) / 2));
        }
        return null;

このエラーが発生する理由と、コードのどこが間違っているのでしょうか?

4

1 に答える 1

2

を同期してみてくださいmapOverlays.add(itemizedOverlay);。これが問題だと思います.複数のスレッドが同時に追加しようとしています.

于 2012-10-30T10:11:56.133 に答える