Array Index Out Of Bound Exception

Put problem concerning MapActivities, MapViews, Overlays and GPS in this forum.

Array Index Out Of Bound Exception

Postby ashish » Sat May 02, 2009 11:10 am

hello,

For drawing overlay i have written this code...Actually i want to create new overlay on tap event or ontouch event.But problem is that whenever i try to do that , i am getting error..Array Index Out Of Bound Exception just on next touch.so,is there any way to change the overlay item in On Tap or On Touch Event.

please any one????????????????



public class map extends MapActivity
{


public MapView mapView;
ZoomControls mZoom;
LinearLayout linearlayout;
Canvas canvas;
Paint paint;
List<Overlay> mapOverlays;
Drawable drawable;
Drawable drawable2;
HelloItemizedOverlay itemizedOverlay;
HelloItemizedOverlay itemizedOverlay2;
Spinner mMenuMode;
ListView listView;
GeoPoint point2;


Location mylocation1;
Location mylocation2;

MapController mc;
/** Called when the activity is first created. */
@Override
public void onCreate(Bundle icicle)
{
super.onCreate(icicle);
//mapView=new MapView(this,"0JFbwZNdCwAQKAvMfhbYVMcVpBScAbXw1GRWneg");

setContentView(R.layout.main);



linearlayout=(LinearLayout)findViewById(R.id.zoomview);

mapView = (MapView) findViewById(R.id.mapview);
mZoom=(ZoomControls) mapView.getZoomControls();
linearlayout.addView(mZoom);


mapOverlays =mapView.getOverlays();

drawable=this.getResources().getDrawable(R.drawable.bubble);


itemizedOverlay = new HelloItemizedOverlay(drawable);

GeoPoint point = new GeoPoint(19240000,-99120000);



OverlayItem overlayitem1 = new OverlayItem(point, "", "item1");

point2 = new GeoPoint(35410000, 139460000);
OverlayItem overlayitem2 = new OverlayItem(point2, "", "item2");

GeoPoint point3 = new GeoPoint(36410000, 149460000);
OverlayItem overlayitem3 = new OverlayItem(point3, "", "item3");





itemizedOverlay.addOverlay(overlayitem1);
itemizedOverlay.addOverlay(overlayitem2);
itemizedOverlay.addOverlay(overlayitem3);

mapOverlays.add(itemizedOverlay);


}








@Override
protected boolean isRouteDisplayed()
{
// TODO Auto-generated method stub
return false;
}



class HelloItemizedOverlay extends ItemizedOverlay <OverlayItem>{

PopupWindow popwin=new PopupWindow(map.this);
private ArrayList<OverlayItem> mOverlays = new ArrayList<OverlayItem>();
GeoPoint point2;

Geocoder gc;

public void draw(Canvas canvas, MapView mapView, boolean shadow) {

Log.i("TAG", "<<<<<<<<<<<<<<<<<<<<<<<draw called...........");


super.draw(canvas, mapView, shadow);

}


public HelloItemizedOverlay(Drawable defaultMarker) {
super(boundCenterBottom(defaultMarker));

// TODO Auto-generated constructor
}

@Override
protected OverlayItem createItem(int i) {
// TODO Auto-generated method stub

return mOverlays.get(i);
}

@Override
public int size() {
// TODO Auto-generated method stub
return mOverlays.size();
}

public void addOverlay(OverlayItem overlay) {
mOverlays.add(overlay);
populate();
}


public boolean onTouchEvent(MotionEvent event, MapView mapView)
{
Log.i("","<<<<<<<<<<on touch event called..");



return false;

}



protected boolean onTap(int pIndex)
{
Log.i("","<<<<<<<<<onTap called..."+pIndex);


itemizedOverlay.mOverlays.clear();
mapOverlays.clear();


GeoPoint point = new GeoPoint(19250000,-99170000);

OverlayItem overlayitem1 = new OverlayItem(point, "", "item1");
itemizedOverlay.addOverlay(overlayitem1);
mapOverlays.add(itemizedOverlay);



return false;

}




}





}
ashish
Experienced Developer
Experienced Developer
 
Posts: 62
Joined: Fri Feb 20, 2009 8:09 am

Top

Postby raim1312 » Fri Apr 09, 2010 1:29 am

I'm not sure myself.
For me I remove a specific overlay item from the ArrayList<OverlayItem> and then if the user touchs the spot where the overlay item once was the application crashes with an ArrayIndexOutOfBounds exception. I've tried catching this exception all over my code but can't figure out whats throwing it.

I read an idea to call invalidate() on the enclosing map but that didn't work for me.
raim1312
Junior Developer
Junior Developer
 
Posts: 16
Joined: Fri Apr 09, 2010 1:24 am
Location: RI

Postby YellowJK » Fri Apr 09, 2010 3:28 am

i also had this problem, and i stumbled across the answer to this problem today

http://developmentality.wordpress.com/2 ... rkarounds/

basicly just call
Syntax: [ Download ] [ Hide ]
Using java Syntax Highlighting
  1. setLastFocusedIndex(-1);
Parsed in 0.031 seconds, using GeSHi 1.0.8.4
when ever you modify your overlay array before you call
Syntax: [ Download ] [ Hide ]
Using java Syntax Highlighting
  1. populate();
Parsed in 0.030 seconds, using GeSHi 1.0.8.4
YellowJK
Freshman
Freshman
 
Posts: 9
Joined: Fri Apr 09, 2010 12:19 am

Re: Array Index Out Of Bound Exception

Postby I82Much » Fri Jul 02, 2010 5:53 pm

That's my blog, glad you stumbled upon it. Crazy that they still haven't fixed that bug. What a pain.
I82Much
Freshman
Freshman
 
Posts: 2
Joined: Fri Jul 02, 2010 5:53 pm

Top

Return to Map Problems

Who is online

Users browsing this forum: Exabot [Bot] and 7 guests