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 880967
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 15, 20262026-05-15T12:11:08+00:00 2026-05-15T12:11:08+00:00

As the title suggest i have (sometimes) a concurrentmodificationexception while trying to create a

  • 0

As the title suggest i have (sometimes) a concurrentmodificationexception while trying to create a route between two locations …
Here is my code (and in case you’re wondering MyOverlay does not try to access the other Overlays in the map)

    private class fillRouteTask extends AsyncTask<Void, GeoPoint, Void> {

  /**
   * create the url to call to get the route
   * 
   * @param src
   * @param dest
   * @return
   */
  private StringBuilder createUrl(GeoPoint src, GeoPoint dest) {
   // connect to map web service
   StringBuilder urlString = new StringBuilder();
   urlString.append("http://maps.google.com/maps?f=d&hl=en");
   urlString.append("&saddr=");// from
   urlString.append(Double
     .toString((double) src.getLatitudeE6() / 1.0E6));
   urlString.append(",");
   urlString.append(Double
     .toString((double) src.getLongitudeE6() / 1.0E6));
   urlString.append("&daddr=");// to
   urlString.append(Double
     .toString((double) dest.getLatitudeE6() / 1.0E6));
   urlString.append(",");
   urlString.append(Double
     .toString((double) dest.getLongitudeE6() / 1.0E6));
   urlString.append("&ie=UTF8&0&om=0&output=kml");
   Log.d("xxx", "URL=" + urlString.toString());

   return urlString;
  }

  /**
   * create the connection to google url
   * 
   * @param src
   * @param dest
   * @return
   */
  private String connectToUrl(GeoPoint src, GeoPoint dest) {

   // get the kml (XML) doc. And parse it to get the
   // coordinates(direction
   // route).
   Document doc = null;
   HttpURLConnection urlConnection = null;
   URL url = null;
   try {
    url = new URL(createUrl(src, dest).toString());
    urlConnection = (HttpURLConnection) url.openConnection();
    urlConnection.setRequestMethod("GET");
    urlConnection.setDoOutput(true);
    urlConnection.setDoInput(true);
    urlConnection.connect();

    DocumentBuilderFactory dbf = DocumentBuilderFactory
      .newInstance();
    DocumentBuilder db = dbf.newDocumentBuilder();
    doc = db.parse(urlConnection.getInputStream());

    if (doc.getElementsByTagName("GeometryCollection") != null
      && doc.getElementsByTagName("GeometryCollection")
        .getLength() > 0) {
     return doc.getElementsByTagName("GeometryCollection").item(
       0).getFirstChild().getFirstChild().getFirstChild()
       .getNodeValue();
    }

   } catch (MalformedURLException e) {
    Log.d("test", e.getLocalizedMessage());
   } catch (IOException e) {
    Log.d("test", e.getLocalizedMessage());
   } catch (ParserConfigurationException e) {
    Log.d("test", e.getLocalizedMessage());
   } catch (SAXException e) {
    Log.d("test", e.getLocalizedMessage());
   }
   return null;
  }

  protected Void doInBackground(Void... arg0) {
   try {
    // get the current overlays present in the map
    List<Overlay> overs = Collections.synchronizedList(mapView
      .getOverlays());
    String path = connectToUrl(orig, dest);
    if (path != null) {
     Log.d("xxx", "path=" + path);
     String[] pairs = path.split(" ");
     String[] lngLat = pairs[0].split(",");

     GeoPoint startGP = new GeoPoint((int) (Double
       .parseDouble(lngLat[1]) * 1E6), (int) (Double
       .parseDouble(lngLat[0]) * 1E6));

     overs.add(new MyOverlay(startGP, startGP, 1));
     GeoPoint gp1;
     GeoPoint gp2 = startGP;
     for (int i = 1; i < pairs.length; i++) // the last one would
     // be
     // crash
     {
      lngLat = pairs[i].split(",");
      gp1 = gp2;
      // watch out! For GeoPoint, first:latitude,
      // second:longitude
      gp2 = new GeoPoint(
        (int) (Double.parseDouble(lngLat[1]) * 1E6),
        (int) (Double.parseDouble(lngLat[0]) * 1E6));
      Log.d("xxx", "pair:" + pairs[i]);
      publishProgress(gp1, gp2);
     }
     overs.add(new MyOverlay(dest, dest, 3)); // use
     // the
     // default
     // color
     drawn = false;
    } else {
     m_handler.post(new Runnable() {

      public void run() {
       Toast.makeText(getApplicationContext(),
         "Problem in getting the directions",
         Toast.LENGTH_SHORT).show();
      }
     });
    }
   } catch (Exception e) {
    m_handler.post(new Runnable() {

     public void run() {
      Toast.makeText(getApplicationContext(),
        R.string.errorrouteLoad, Toast.LENGTH_LONG)
        .show();
     }
    });
   }
   return null;

  }

  /*
   * (non-Javadoc)
   * 
   * @see android.os.AsyncTask#onProgressUpdate(Progress[])
   */
  @Override
  protected void onProgressUpdate(GeoPoint... values) {
   // TODO Auto-generated method stub
   List<Overlay> overs = Collections.synchronizedList(mapView
     .getOverlays());
   overs.add(new MyOverlay(values[0], values[1], 2, 0x0000ff));

  }

  /*
   * (non-Javadoc)
   * 
   * @see android.os.AsyncTask#onPostExecute(java.lang.Object)
   */
  @Override
  protected void onPostExecute(Void result) {
   // TODO Auto-generated method stub
   Log.d("routing", "done");
   mapView.postInvalidate();
  }
 }
  • 1 1 Answer
  • 1 View
  • 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-05-15T12:11:08+00:00Added an answer on May 15, 2026 at 12:11 pm

    You can only modify overlays on the UI thread. You need to add the new data to the overlay in the onPostExecute method of AsyncTask.

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

Sidebar

Related Questions

I a have code segment : <button class=awe-btn onclick=<%:Url.Awe().PopupFormAction().Url(Url.Action(create)).Success(create).Title(create dinner) %>>Create</button> that are MVC
As the title may suggest, I have been using jQuery AJAX to try and
Can anyone suggest how to underline the title of a UIButton ? I have
I have following code in html file: <html> <head> <title>My Great Website</title> </head> <body>
I have an issue trying to persist entities to the DB using code-first technique.
(I wish I could have come up with a more descriptive title... suggest one
the title might suggest it, but i'm looking for a way to have Facebooks
Hey all so as the title suggest I just have a date picker and
As the title says - Here I have a link which contains img tag:
Forgive the title, wasn't sure what to put. I have some code like: var

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.