Cant convert String to double


So I got the latitude and longitude and successfully saved it on firebase, and now I was able to retrieve it and paste their values on a TextView.

I am planning to get the string value from the TextView and convert it to double and use that as a latitude and longitude to show a location on a map. I followed the format for converting string value to double value and it still wont work.

This is my code:

public void onMapReady(GoogleMap googleMap) {
mMap = googleMap;

    String latitude = textViewLatt.getText().toString();
    String longitude = textViewLong.getText().toString();

    //Double latitude = Double.valueOf(textViewLatt.getText().toString());
    //Double longitude = Double.valueOf(textViewLong.getText().toString());

    double latt = Double.parseDouble(latitude);
    double longi= Double.parseDouble(longitude);

    //double latt = Double.valueOf(latitude);
    //double longi = Double.valueOf(longitude);

    // Add a marker in Sydney and move the camera
    LatLng sydney = new LatLng(latt, longi);
    mMap.addMarker(new MarkerOptions()

and these are the errors I got from debugging, I tried to search the problem and I couldnt find any solutions. Any help will be great.

enter image description here

enter image description here


Update: I found the problem, it seems like its getting the value even before I change the textview’s value into numbers. thus it was trying to convert "latitude"(the previous value of the textview) to a double and instead of the coordinates.

Thank you for your suggestions guys!

Answered By – Timow

This Answer collected from stackoverflow, is licensed under cc by-sa 2.5 , cc by-sa 3.0 and cc by-sa 4.0

Leave a Reply

(*) Required, Your email will not be published