1

please guide what mistake am i doing here? any help would be appreciated.

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)
2
  • you're doing smting like this ArrayList<int> arr = new ArrayList<int>(); arr.add(1); arr.add(2); arr.add(3); /* from here */ for(int i:arr){arr.add(5);} ... in other word you modify collection when you iterate it Commented Jun 9, 2011 at 14:22
  • i am not modifying collection anywhere... Commented Jun 10, 2011 at 7:56

1 Answer 1

5

i got answer my self.

actually mapOverlays.add(itemizedOverlay); needs ui to run.

so it was not ui thread thats why it was raising error.

i just ran that function in uithread and which resolved my problem.

Sign up to request clarification or add additional context in comments.

2 Comments

Thanks for the tip about mapOverlays.add(itemizedOverlay) needing UI to run. I am trying to use it in an AsyncTask and doing the mapOverlays.add(itemizedOverlay) in the onPostExecute method since that provides UI access. However, clicking on the overlay item crashes the app with the message: "android.view.WindowManager$BadTokenException: Unable to add window -- token null is not for an application". What is the correct way to add the overlays in an AsyncTask? BTW, I should mention, the overlay items worked just fine before I moved to the AsyncTask approach.
This will certainly fix the error. However, the correct answer will say that because you are adding elements to your mapOverlays array in more than one Thread, you need to prevent several Threads froma adding to your array at the same time. Using the UI thread fixes the error, because there's only one UI thread, and by forcing the usage of it, you prevent many threads from writing in mapOverlays array, only UI thread will do.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.