Numberformatexception In Android, Parsedouble Geopoint
Having this problem with my android app I struggled with this for some time now, and went through alot of similar threads but never really solved it. I haven't managed to recreate
Solution 1:
You're not handling the NumberFormatException
in the first place, which is bad practice even if you weren't having crashes. Split that line up, parse the doubles first, and be sure to catch the NumberFormatException
and handle it appropriately (e.g. throw an alert dialog, place a default value, etc.) in case for some reason the value in getLat()
or getLon()
are not parseable, which is what is apparently happening in these cases.
double lat = 0, lng = 0;
String sLat = sitesList.getLat().get(i);
String sLng = sitesList.getLng().get(i);
GeoPoint point;
try {
lat = Double.parseDouble(sLat);
lng = Double.parseDouble(sLng);
//If it gets here, they parsed successfully
point = new GeoPoint((int)(lat * 1e6), (int)(lng * 1e6));
} catch (NumberFormatException e) {
Log.e("TAG", "Couldn't parse latitude and/or longitude");
}
Post a Comment for "Numberformatexception In Android, Parsedouble Geopoint"