Note that there are some explanatory texts on larger screens.

plurals
  1. POunable to remove marker onTap
    text
    copied!<p>I'm developing an Android app where a user can add a marker tapping on the screen; it works, but i have a problem when I want to remove one of the markers by tapping it; here is my code (i followed the NooYawk example):</p> <pre><code>private class PoiOverlay extends ItemizedOverlay&lt;MyOverlayItem&gt;{ private ArrayList&lt;MyOverlayItem&gt; mOverlays = new ArrayList&lt;MyOverlayItem&gt;(); public PoiOverlay() { super(null); populate(); // TODO Auto-generated constructor stub } @Override protected boolean onTap(int index) { Log.d("toccato",":"+index); mOverlays.remove(index); doPopulate(); return true; } public boolean onTap(GeoPoint point, MapView view) { if (super.onTap(point, view)) return true; int icon; if (type==1) icon=R.drawable.bluedot; else icon=R.drawable.reddot; MyOverlayItem overlay=new MyOverlayItem(point, ""+id, ""+id, id, icon); addOverlay(overlay); doPopulate(); Poi poi=new Poi(id, point, type); pois.addLast(poi); inserted.addLast(id); id+=1; return true; } public void doPopulate(){ setLastFocusedIndex(-1); populate(); } public void addOverlay(MyOverlayItem overlay){ Drawable drawable=getMarker(overlay.markerInt); overlay.marker=drawable; mOverlays.add(overlay); populate(); } </code></pre> <p>But it doesn't work. I'm able to add markers, but when I try to remove one of them i get an Array out of bounds exception, and I don't know why.</p> <p>This is the excpetion I got when tapping on a marker:</p> <pre><code> 02-04 22:17:29.418: ERROR/AndroidRuntime(9979): FATAL EXCEPTION: main 02-04 22:17:29.418: ERROR/AndroidRuntime(9979): java.lang.IndexOutOfBoundsException: Invalid index 1, size is 1 02-04 22:17:29.418: ERROR/AndroidRuntime(9979): at java.util.ArrayList.throwIndexOutOfBoundsException(ArrayList.java:257) 02-04 22:17:29.418: ERROR/AndroidRuntime(9979): at java.util.ArrayList.get(ArrayList.java:311) 02-04 22:17:29.418: ERROR/AndroidRuntime(9979): at com.google.android.maps.ItemizedOverlay.getItem(ItemizedOverlay.java:419) 02-04 22:17:29.418: ERROR/AndroidRuntime(9979): at com.google.android.maps.ItemizedOverlay.focus(ItemizedOverlay.java:538) 02-04 22:17:29.418: ERROR/AndroidRuntime(9979): at com.google.android.maps.ItemizedOverlay.onTap(ItemizedOverlay.java:455) 02-04 22:17:29.418: ERROR/AndroidRuntime(9979): at offscreen.tagger.Main$PoiOverlay.onTap(Main.java:280) 02-04 22:17:29.418: ERROR/AndroidRuntime(9979): at com.google.android.maps.OverlayBundle.onTap(OverlayBundle.java:83) 02-04 22:17:29.418: ERROR/AndroidRuntime(9979): at com.google.android.maps.MapView$1.onSingleTapUp(MapView.java:347) 02-04 22:17:29.418: ERROR/AndroidRuntime(9979): at com.google.android.maps.GestureDetector.onTouchEvent(GestureDetector.java:533) 02-04 22:17:29.418: ERROR/AndroidRuntime(9979): at com.google.android.maps.MapView.onTouchEvent(MapView.java:647) 02-04 22:17:29.418: ERROR/AndroidRuntime(9979): at android.view.View.dispatchTouchEvent(View.java:3765) 02-04 22:17:29.418: ERROR/AndroidRuntime(9979): at android.view.ViewGroup.dispatchTouchEvent(ViewGroup.java:905) 02-04 22:17:29.418: ERROR/AndroidRuntime(9979): at android.view.ViewGroup.dispatchTouchEvent(ViewGroup.java:944) 02-04 22:17:29.418: ERROR/AndroidRuntime(9979): at android.view.ViewGroup.dispatchTouchEvent(ViewGroup.java:944) 02-04 22:17:29.418: ERROR/AndroidRuntime(9979): at android.view.ViewGroup.dispatchTouchEvent(ViewGroup.java:944) 02-04 22:17:29.418: ERROR/AndroidRuntime(9979): at android.view.ViewGroup.dispatchTouchEvent(ViewGroup.java:944) 02-04 22:17:29.418: ERROR/AndroidRuntime(9979): at com.android.internal.policy.impl.PhoneWindow$DecorView.superDispatchTouchEvent(PhoneWindow.java:1701) 02-04 22:17:29.418: ERROR/AndroidRuntime(9979): at com.android.internal.policy.impl.PhoneWindow.superDispatchTouchEvent(PhoneWindow.java:1116) 02-04 22:17:29.418: ERROR/AndroidRuntime(9979): at android.app.Activity.dispatchTouchEvent(Activity.java:2093) 02-04 22:17:29.418: ERROR/AndroidRuntime(9979): at com.android.internal.policy.impl.PhoneWindow$DecorView.dispatchTouchEvent(PhoneWindow.java:1685) 02-04 22:17:29.418: ERROR/AndroidRuntime(9979): at android.view.ViewRoot.handleMessage(ViewRoot.java:1802) 02-04 22:17:29.418: ERROR/AndroidRuntime(9979): at android.os.Handler.dispatchMessage(Handler.java:99) 02-04 22:17:29.418: ERROR/AndroidRuntime(9979): at android.os.Looper.loop(Looper.java:144) 02-04 22:17:29.418: ERROR/AndroidRuntime(9979): at android.app.ActivityThread.main(ActivityThread.java:4937) 02-04 22:17:29.418: ERROR/AndroidRuntime(9979): at java.lang.reflect.Method.invokeNative(Native Method) 02-04 22:17:29.418: ERROR/AndroidRuntime(9979): at java.lang.reflect.Method.invoke(Method.java:521) 02-04 22:17:29.418: ERROR/AndroidRuntime(9979): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:868) 02-04 22:17:29.418: ERROR/AndroidRuntime(9979): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:626) 02-04 22:17:29.418: ERROR/AndroidRuntime(9979): at dalvik.system.NativeStart.main(Native Method) </code></pre>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload