Commit 452eb6d3 authored by halatmit's avatar halatmit Committed by Gerrit Review System

Fix location sensor to not crash when geoserver returns empty AddressObjs list

Change-Id: I2edfdad4ed3b56519fa8d29d2e54f193c276febf
parent 74747d31
......@@ -439,9 +439,20 @@ public class LocationSensor extends AndroidNonvisibleComponent
return sb.toString();
}
}
} catch (IOException e) {
Log.e("LocationSensor",
"Exception thrown by getFromLocation() " + e.getMessage());
} catch (Exception e) {
// getFromLocation can throw an IOException or an IllegalArgumentException
// a bad result can give an indexOutOfBoundsException
// are there others?
if (e instanceof IllegalArgumentException
|| e instanceof IOException
|| e instanceof IndexOutOfBoundsException ) {
Log.e("LocationSensor", "Exception thrown by getting current address " + e.getMessage());
} else {
// what other exceptions can happen here?
Log.e("LocationSensor",
"Unexpected exception thrown by getting current address " + e.getMessage());
}
}
}
return "No address available";
......@@ -458,7 +469,8 @@ public class LocationSensor extends AndroidNonvisibleComponent
public double LatitudeFromAddress(String locationName) {
try {
List<Address> addressObjs = geocoder.getFromLocationName(locationName, 1);
if (addressObjs == null) {
Log.i("LocationSensor", "latitude addressObjs size is " + addressObjs.size() + " for " + locationName);
if ( (addressObjs == null) || (addressObjs.size() == 0) ){
throw new IOException("");
}
return addressObjs.get(0).getLatitude();
......@@ -479,7 +491,8 @@ public class LocationSensor extends AndroidNonvisibleComponent
public double LongitudeFromAddress(String locationName) {
try {
List<Address> addressObjs = geocoder.getFromLocationName(locationName, 1);
if (addressObjs == null) {
Log.i("LocationSensor", "longitude addressObjs size is " + addressObjs.size() + " for " + locationName);
if ( (addressObjs == null) || (addressObjs.size() == 0) ){
throw new IOException("");
}
return addressObjs.get(0).getLongitude();
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment