我已經試過類似下面爲什麼getCurrentLattitude()的返回值會引發數字格式異常?
double latitude = 0;
double longitude = 0;
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.places_details_gridview);
locManager = (LocationManager) getSystemService(LOCATION_SERVICE);
currentLoc = new CurrentLocation(locManager, ShowPlacesInList.this);
if(currentLoc.getCurrentLattitude() != null && currentLoc.getCurrentLongitude() != null){
latitude = Double.parseDouble(currentLoc.getCurrentLattitude());
longitude = Double.parseDouble(currentLoc.getCurrentLongitude());
myLoc = new Location("");
myLoc.setLatitude(latitude);
myLoc.setLongitude(longitude);
calculateDist();
}
}
它顯示我得到一個字符串值
什麼是無法解析的返回值? –
檢查currentLoc.getCurrentLattitude()的值..您將得到答案 – stinepike
傳遞給Double.parseDouble()的字符串值格式不正確。在logcat中打印並在這裏發佈。 – Melquiades