java - IndexOutOfBounds Exception when filling multidimensional array -
i have xml data looping through. store each "entry" in array spot in order see intent.putextras(). data has 3 elements: latlon,name,description. put each in array. setting so: markerinfo[i][0] = loc; etc... so:
final list<xmldom> entries = xml.tags("placemark"); int = entries.size(); int j=0; (xmldom entry : entries) { xmldom lon = entry.tag("longitude"); xmldom lat = entry.tag("latitude"); xmldom name = entry.tag("name"); xmldom desc = entry.tag("description"); string cdatareplace = desc.tostring(); string description = cdatareplace.replace("<![cdata[", ""); description = description.replace("]]>", ""); final string firename = name.text(); final string firedesc = description; string geolon = lon.text(); string geolat = lat.text(); string coor = lat + "," + lon; // log.e("coors: ", coor); double lati = double.parsedouble(geolat); double lngi = double.parsedouble(geolon); location = new latlng(lati, lngi); string loc = location.tostring(); string[][] markerinfo = new string[i][3]; markerinfo[j][0] = loc; markerinfo[j][1] = firename; markerinfo[j][2] = firedesc; log.e("markerinfo",markerinfo[j][0]); log.e("markerinfo",markerinfo[j][1]); log.e("markerinfo",markerinfo[j][2]); map.addmarker(new markeroptions() .position(location) .title(markerinfo[j][1]) .snippet(markerinfo[j][2]) .icon(bitmapdescriptorfactory .fromresource(r.drawable.wfmi_icon48))); map.setoninfowindowclicklistener(new oninfowindowclicklistener() { @override public void oninfowindowclick(marker arg0) { // show full description in new activity. // firedesc(arg0.gettitle(), arg0.getsnippet()); intent = new intent(map.this, mapsingleactivity.class); i.putextra("name", arg0.gettitle()) .putextra("description", arg0.getsnippet()) .putextra("lat", arg0.getposition().latitude) .putextra("lon", arg0.getposition().longitude); i.addflags(intent.flag_activity_clear_top); startactivity(i); } }); j++; }
i getting array index out of bounds. figured if filled entries.size() not problem, maybe not telling how big correctly?
thanks help
you need make sure second dimension big enough
fix changing declaration of markerinfo
to:
string[][] markerinfo = new string[i][3];
at moment creating i
empty string
arrays. above code create i
arrays can hold 3 string
objects each.
also, @ moment writing last location outside of array bounds.
you need change write available location. if trying write last available location i-1
.
markerinfo[i-1][0] = loc; markerinfo[i-1][1] = firename; markerinfo[i-1][2] = firedesc;
looking @ code however, seems may want declare markerinfo
outside of loop , create counter variable increment @ each step of loop.
Comments
Post a Comment