I am developing an Andorid application and I am having troubles with a line of code. I am getting x and y coordinates that have been stored as strings then I try to convert them to integers with x = (int) Long.parseLong(loc1); (x is an int). I have tried the parseInt also, and has not worked. Any ideas? Thank you.

5 Years
Discussion Span
Last Post by JamesCherrill
    When I comment out the lines x = (int) Long.parseLong(loc1); and y = (int) Long.parseLong(loc2); the app works fine, which means that it loads the map and places a custom pinpoint on the map. This code is executed when Google Maps is loaded. It opens my database (addSpot.open()) , gets the x,y coordinates for saved locations, then puts them into tempA array. Then I want to convert an x , y coordinates to integers (strings first) by using the Long.parseLong. Any suggestions? 

        locUse = addSpot.getDataForMapLocation();
            String myLocationTest = "";
            String tempA[];

            AlertDialog alert = new AlertDialog.Builder(map.this).create();

            tempA = locUse.split(",");

            String loc1,loc2;
            loc1 = tempA[3];
            loc2 = tempA[4];

            x = (int) Long.parseLong(loc1);
            y = (int) Long.parseLong(loc2);

            touchedPoint = map.getProjection().fromPixels(x,y);
            OverlayItem overlayItem = new OverlayItem(touchedPoint, "Hunting Spot", "Nice Spot");
            CustomPinpoint custom = new CustomPinpoint(d, map.this);

What are the contents of the Strings you are string to convert?

What happens when the code does "not work"? Are there exceptions and error messages?


loc1 is 354.0
loc2 is 407.00003

There are no exceptions or error messages. I just get a message that says your appliction has stopped unexpectedly. Thanks for your help.


Long is an integer type. Your Strings do not represent an integer. If you put the code in a try/catch block you will probably catch a NumberFormatException
Perhaps you confused long (integer) with double (floating point)?

This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.