当我从计时器调用此函数时,为什么尝试抛出绑定异常的数组。
我该如何解决这个查询。此代码在 run 函数之间调用。list<Address> addresses
是超出范围的数组异常。告诉我一些解决此查询的方法
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 look up failed";
//return address;
}
}
else
{
address="Geocoder is not present";
//return address;
}
return address;
}