我不時得到這個異常,當我從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 –
因此,雙解析將失敗,因爲它包含逗號字符。 –