Monday, 15 September 2014

android - Why this array throws an array out of bound exception -



android - Why this array throws an array out of bound exception -

when phone call function timer why seek throw array our of bound exception.

how can solve query. code called in between run function. list<address> addresses go out of bound array exception. tell me way solve query

public string get_address(double latitude ,double longitude) { string address = null; if(geocoder.ispresent()) { try{ geocoder geocoder2 = new geocoder(mcontext, locale.getdefault()); list<address> addresses; addresses = geocoder2.getfromlocation(latitude, longitude, 2); if(addresses != null) { address returnedaddress = addresses.get(0); stringbuilder strreturnedaddress = new stringbuilder("address:\n"); for(int i=0; i<returnedaddress.getmaxaddresslineindex(); i++) { strreturnedaddress.append(returnedaddress.getaddressline(i)).append("\n"); } /*if(returnedaddress.getmaxaddresslineindex() > 0){ strreturnedaddress.append(returnedaddress.getaddressline(0) + ", "); } strreturnedaddress.append(returnedaddress.getlocality() + ", "); strreturnedaddress.append(returnedaddress.getcountryname()); */ address=strreturnedaddress.tostring(); } else{ address="no address returned!"; } //return address; } catch(exception e) { log.e("myapp", "reverse geo lookup failed", e); address="reverse geo failed"; //return address; } } else { address="geocoder not present"; //return address; } homecoming address; }

addresses can empty(so different null can't first item)

replace if(addresses != null) if(addresses != null && !addresses.isempty())

android android-layout android-intent android-emulator

No comments:

Post a Comment