简体   繁体   中英

Why does the return value of getCurrentLattitude() throws number format exception?

I have tried something like below

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();
    }  
}

It showing number format exception in the

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

from currentLoc.getLatitude and currentloc.getLongitude i am getting a string value

Please read this .

Make sure that you are using correct decimal separator (depending on Locale valid Double may be 5.0 or 5,0).

from currentLoc.getLatitude and currentloc.getLongitude i am getting a string value

What string value?

The parseDouble method throws a NumberFormatException when "the string does not contain a parsable double" - http://docs.oracle.com/javase/7/docs/api/java/lang/Double.html#parseDouble(java.lang.String)

The NumberFormatException that is thrown will show you exactly what the problem is eg:

java.lang.NumberFormatException: For input string: "A5.0"

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM