Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8837089
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 14, 20262026-06-14T09:38:20+00:00 2026-06-14T09:38:20+00:00

I’ve an app that uses a google mapview. The code works fine on my

  • 0

I’ve an app that uses a google mapview. The code works fine on my old device android 2.1 but on my htc one x running android 4 i’ve had to Async it to avoid network on main thread exception.

The mapview shows foe about a second then it crashes. The error contains an exception that refers to a thread not calling Looper.prepare(). Any ideas how i can solve it thanks.

Here’s the exception and i’ll post the source below.

11-14 13:29:31.025: W/dalvikvm(20404): threadid=15: thread exiting with uncaught exception (group=0x40a7d228)
11-14 13:29:31.025: E/AndroidRuntime(20404): FATAL EXCEPTION: AsyncTask #4
11-14 13:29:31.025: E/AndroidRuntime(20404): java.lang.RuntimeException: An error occured while executing doInBackground()
11-14 13:29:31.025: E/AndroidRuntime(20404):    at android.os.AsyncTask$3.done(AsyncTask.java:278)
11-14 13:29:31.025: E/AndroidRuntime(20404):    at java.util.concurrent.FutureTask$Sync.innerSetException(FutureTask.java:273)
11-14 13:29:31.025: E/AndroidRuntime(20404):    at java.util.concurrent.FutureTask.setException(FutureTask.java:124)
11-14 13:29:31.025: E/AndroidRuntime(20404):    at java.util.concurrent.FutureTask$Sync.innerRun(FutureTask.java:307)
11-14 13:29:31.025: E/AndroidRuntime(20404):    at java.util.concurrent.FutureTask.run(FutureTask.java:137)
11-14 13:29:31.025: E/AndroidRuntime(20404):    at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1076)
11-14 13:29:31.025: E/AndroidRuntime(20404):    at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:569)
11-14 13:29:31.025: E/AndroidRuntime(20404):    at java.lang.Thread.run(Thread.java:864)
11-14 13:29:31.025: E/AndroidRuntime(20404): Caused by: java.lang.RuntimeException: Can't create handler inside thread that has not called Looper.prepare()
11-14 13:29:31.025: E/AndroidRuntime(20404):    at android.os.Handler.<init>(Handler.java:121)
11-14 13:29:31.025: E/AndroidRuntime(20404):    at android.widget.ZoomButtonsController$2.<init>(ZoomButtonsController.java:170)
11-14 13:29:31.025: E/AndroidRuntime(20404):    at android.widget.ZoomButtonsController.<init>(ZoomButtonsController.java:170)
11-14 13:29:31.025: E/AndroidRuntime(20404):    at com.google.android.maps.MapView.createZoomButtonsController(MapView.java:1444)
11-14 13:29:31.025: E/AndroidRuntime(20404):    at com.google.android.maps.MapView.setBuiltInZoomControls(MapView.java:1498)
11-14 13:29:31.025: E/AndroidRuntime(20404):    at com.carefreegroup.GetClientDirections.getRoute(GetClientDirections.java:173)
11-14 13:29:31.025: E/AndroidRuntime(20404):    at com.carefreegroup.GetClientDirections$AsyncGetRoute.doInBackground(GetClientDirections.java:87)
11-14 13:29:31.025: E/AndroidRuntime(20404):    at com.carefreegroup.GetClientDirections$AsyncGetRoute.doInBackground(GetClientDirections.java:1)
11-14 13:29:31.025: E/AndroidRuntime(20404):    at android.os.AsyncTask$2.call(AsyncTask.java:264)
11-14 13:29:31.025: E/AndroidRuntime(20404):    at java.util.concurrent.FutureTask$Sync.innerRun(FutureTask.java:305)

.

public class GetClientDirections extends MapActivity {

    private MapController mapController;
    private MapView mapView;

    private List<Overlay> mapOverlays;
    private StringBuffer response = null;
    private static final String TAG = GetClientDirections.class.getSimpleName();
    private double lon;
    private double lat;
    private JSONArray routes = null;
    private JSONObject bounds = null;
    private JSONObject northeast = null;
    private JSONObject anonObject;
    private JSONObject overViewPolyline;
    private String stringUrl;
    private String polyPoints;
    Context context;
    private String endAddr;
    private String startAddr;

    /** Called when the activity is first created. */
    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.mapview);

        context = this;
        startAddr = "wf120lj";
        endAddr = "wf27ar";



                StringBuilder sb = new StringBuilder();
                sb.append("http://maps.google.com/maps/api/directions/json?origin=");
                sb.append(startAddr);
                sb.append("&destination=");
                sb.append(endAddr);
                sb.append("&sensor=false");

                stringUrl = sb.toString();
                Log.e(TAG, "url = " + stringUrl);


                AsyncGetRoute agr = new AsyncGetRoute();
                agr.execute();




    }// end of onCreate


    private class AsyncGetRoute extends AsyncTask<Void, Void, Void> {



        @Override
        protected Void doInBackground(Void... params) {

            getRoute();
            return null;
        }


    }





    public void getRoute() {

        response = new StringBuffer();
        URL url = null;
        try {
            url = new URL(stringUrl);
        } catch (MalformedURLException e) {
            // TODO Auto-generated catch block
            e.printStackTrace();
        }
        HttpURLConnection httpconn = null;
        try {
            httpconn = (HttpURLConnection) url.openConnection();
        } catch (IOException e1) {
            // TODO Auto-generated catch block
            e1.printStackTrace();
        }
        try {
            if (httpconn.getResponseCode() == HttpURLConnection.HTTP_OK) {
                // Log.e(TAG,"response code OK ");
                BufferedReader input = new BufferedReader(
                        new InputStreamReader(httpconn.getInputStream()), 8192);
                String strLine = null;

                while ((strLine = input.readLine()) != null) {
                    // Log.e(TAG,""+strLine);
                    response.append(strLine);
                }
                input.close();
            }
        } catch (IOException e) {
            // TODO Auto-generated catch block
            e.printStackTrace();
        }

        String jsonOutput = response.toString();
        Log.e(TAG, "jsonOutput = " + jsonOutput);

        JSONObject results = null;
        try {

            results = new JSONObject(jsonOutput);

            routes = results.getJSONArray("routes");

            anonObject = routes.getJSONObject(0);
            bounds = anonObject.getJSONObject("bounds");
            overViewPolyline = anonObject.getJSONObject("overview_polyline");
            polyPoints = overViewPolyline.getString("points");
            Log.e(TAG, "overview_polyline  = " + overViewPolyline);
            Log.e(TAG, "points  = " + polyPoints);

            northeast = bounds.getJSONObject("northeast");

            lat = (Double) northeast.get("lat");

            lon = (Double) northeast.get("lng");

            Log.e(TAG, "lon/lat = " + lon + " " + lat);

        } catch (NumberFormatException e) {
            // TODO Auto-generated catch block
            e.printStackTrace();
        } catch (JSONException e) {
            // TODO Auto-generated catch block
            e.printStackTrace();
        }



        List<GeoPoint> list = decodePoly(polyPoints);



        mapView = (MapView) findViewById(R.id.cfmapview);
        mapView.setBuiltInZoomControls(true);
        mapView.setEnabled(true);
        mapView.setSatellite(true);
        mapController = mapView.getController();
        mapController.setZoom(10);

        mapOverlays = mapView.getOverlays();

        mapOverlays.add(new RoutePathOverlay(list, getApplicationContext()));
        mapController.animateTo(new GeoPoint(list.get(0).getLatitudeE6(), list
                .get(0).getLongitudeE6()));

        mapView.invalidate();

    }// end of getRoute




    private List<GeoPoint> decodePoly(String encoded) {

        List<GeoPoint> poly = new ArrayList<GeoPoint>();
        int index = 0, len = encoded.length();
        int lat = 0, lng = 0;

        while (index < len) {
            int b, shift = 0, result = 0;
            do {
                b = encoded.charAt(index++) - 63;
                result |= (b & 0x1f) << shift;
                shift += 5;
            } while (b >= 0x20);
            int dlat = ((result & 1) != 0 ? ~(result >> 1) : (result >> 1));
            lat += dlat;

            shift = 0;
            result = 0;
            do {
                b = encoded.charAt(index++) - 63;
                result |= (b & 0x1f) << shift;
                shift += 5;
            } while (b >= 0x20);
            int dlng = ((result & 1) != 0 ? ~(result >> 1) : (result >> 1));
            lng += dlng;

            GeoPoint p = new GeoPoint((int) (((double) lat / 1E5) * 1E6),
                    (int) (((double) lng / 1E5) * 1E6));
            poly.add(p);
        }

        return poly;
    }

    @Override
    protected boolean isRouteDisplayed() {
        // TODO Auto-generated method stub
        return false;
    }
}
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-14T09:38:23+00:00Added an answer on June 14, 2026 at 9:38 am

    You shouldn’t update views in doInBackground(), you need to override onPostExecute() and update your MapView there. Split the getRoute() method into two.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a French site that I want to parse, but am running into
I'm parsing an RSS feed that has an &#8217; in it. SimpleXML turns this
I'm making a simple page using Google Maps API 3. My first. One marker
I have a string like this: La Torre Eiffel paragonata all&#8217;Everest What PHP function
link Im having trouble converting the html entites into html characters, (&# 8217;) i
That's pretty much it. I'm using Nokogiri to scrape a web page what has
I want to count how many characters a certain string has in PHP, but
I am reading a book about Javascript and jQuery and using one of the
I've got a string that has curly quotes in it. I'd like to replace
I have a small JavaScript validation script that validates inputs based on Regex. I

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.