我不时得到这个异常,当我从GPS获得一个新的位置坐标,并且我想格式化它。致命异常:java.lang.NumberFormatException
这是我的代码:
DecimalFormat decimalFormat = new DecimalFormat("0.00000");
location.setLatitude(Double.valueOf(decimalFormat.format(location.getLatitude())));
location.setLongitude(Double.valueOf(decimalFormat.format(location.getLongitude())));
为什么会出现这种情况?我从该位置获得的经度和纬度都是双打。我将它转换成需要的格式(小数点后5位小数),然后当我尝试双击时,它会崩溃。为什么会发生?为什么不是每次,有时呢?
例如在什么崩溃:
Fatal Exception: java.lang.NumberFormatException
Invalid double: "52,36959"
这是我使用它:
Log.i("","enteredd latitude is:" + location.getLatitude());
try{
DecimalFormat decimalFormat = new DecimalFormat("0.00000");
location.setLatitude(Double.valueOf(decimalFormat.format(location.getLatitude()).replace(",", ".")));
location.setLongitude(Double.valueOf(decimalFormat.format(location.getLongitude()).replace(",", ".")));
}catch (Exception e){
Log.e("","enteredd error deimal formating" + e.getMessage());
}
Log.i("","enteredd latitude is:" + location.getLatitude());
而且同样的事情:
location = LocationServices.FusedLocationApi.getLastLocation(PSLocationCenter.getInstance().mLocationClient);
问:请问,如果修复我这样做?
location.setLatitude(Double.valueOf(decimalFormat.format(location.getLatitude()).replace(",", ".")));
什么的'location.getLongitude()'和'location.getLongitude()'值是多少? –
我不知道。我遇到Fabric上的崩溃。它使用了很多,如每分钟至少6次,如果正确的活动被打开,则直到60。而我在3天内只有“15人”坠毁。 我所知道的是,我得到:无效的双:“52,36959”所以我猜拉特将类似于52,36959xxx –
因此,双解析将失败,因为它包含逗号字符。 –