2013-12-13 19 views
1

我已經試過類似下面爲什麼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(); 
    } 
} 

它顯示我得到一個字符串值

+1

什麼是無法解析的返回值? –

+2

檢查currentLoc.getCurrentLattitude()的值..您將得到答案 – stinepike

+0

傳遞給Double.parseDouble()的字符串值格式不正確。在logcat中打印並在這裏發佈。 – Melquiades

回答

0

請閱讀this

latitude = Double.parseDouble(currentLoc.getCurrentLattitude()); 

從currentLoc.getLatitude和currentloc.getLongitude數字格式異常。

確保您使用的是正確的小數分隔符(取決於區域設置有效雙精度可能是5.0或5.0)。

相關問題