Hello,

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.

Can you please post the code you're having a problem with?

Also explain what "not worked" means.

    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? 

        addSpot.open();
        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);
            custom.insertPoint(overlayItem);
            overlayList.add(custom);

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)?

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.