title: The content of the adapter has changed but ListView did not receive a notification android google places
body: <p>I am using google places autocomplete and I am getting the following error:
  <strong>(does not happen always only some times)</strong></p>
  
  <pre><code> java.lang.IllegalStateException: The content of the adapter has changed but ListView did not receive a notification. Make sure the content of your adapter is not modified from a background thread, but only from the UI thread. Make sure your adapter calls notifyDataSetChanged() when its content changes. [in ListView(-1, class android.widget.ListPopupWindow$DropDownListView) with Adapter(class locationplacesautocomplete.GooglePlacesAutocompleteAdapter)]
  
   at android.widget.ListView.layoutChildren(ListView.java:1582)
              at android.widget.AbsListView.onLayout(AbsListView.java:2627)
              at android.view.View.layout(View.java:16821)
              at android.view.ViewGroup.layout(ViewGroup.java:5328)
              at android.widget.FrameLayout.layoutChildren(FrameLayout.java:573)
              at android.widget.FrameLayout.onLayout(FrameLayout.java:508)
              at android.view.View.layout(View.java:16821)
              at android.view.ViewGroup.layout(ViewGroup.java:5328)
  </code></pre>
  
  <p>After reading the following message I used runOnUiThread() for notifyDataSetChanged() but still not working.</p>
  
  <p>I will add the adapter class:</p>
  
  <pre><code>package locationplacesautocomplete;
  
  import android.app.Activity;
  import android.content.Context;
  import android.widget.ArrayAdapter;
  import android.widget.Filter;
  import android.widget.Filterable;
  import java.util.ArrayList;
  import java.util.HashMap;
  
  import datatypes.AutoCompleteData;
  
  /**
   * This class implements the adapter for google places auto complete
   * Created by edenbensimon on 07/06/15.
   */
  public class GooglePlacesAutocompleteAdapter extends ArrayAdapter implements Filterable {
  
      // Holds an array list with the results
      private Object[] resultList;
      private HashMap&lt;String, String&gt; result;
      private Activity _activity;
  
      // Default ctor
      public GooglePlacesAutocompleteAdapter(Context context, int textViewResourceId, Activity activity) {
          super(context, textViewResourceId);
          _activity = activity;
      }
  
      @Override
      public int getCount() {
          return resultList.length;
      }
  
      @Override
      public String getItem(int index) {
          return resultList[index].toString();
      }
  
      @Override
      public Filter getFilter() {
          Filter filter = new Filter() {
              @Override
              protected FilterResults performFiltering(CharSequence constraint) {
                  FilterResults filterResults = new FilterResults();
                  if (constraint != null) {
                      // Retrieve the autocomplete results.
                      result = AutoCompleteLogic.autocomplete(constraint.toString());
                      resultList = result.keySet().toArray();
  
                      // Assign the data to the FilterResults
                      filterResults.values = resultList;
                      filterResults.count = resultList.length;
                  }
                  return filterResults;
              }
              @Override
              protected void publishResults(CharSequence constraint, final FilterResults results) {
                  _activity.runOnUiThread(new Runnable() {
                      @Override
                      public void run() {
                          if (results != null &amp;&amp; results.count &gt; 0) {
                              notifyDataSetChanged();
                          } else {
                              notifyDataSetInvalidated();
                          }
                      }
                  });
              }
          };
          return filter;
      }
  
      /**
       * Returns an array list with only description about the place
       */
      private ArrayList getDescOnly(ArrayList values) {
          ArrayList returnValue = new ArrayList&lt;String&gt;();
          for (int i = 0; i &lt; values.size(); i++) {
              returnValue.add(((AutoCompleteData)values.get(i)).getDescription());
          }
  
          return returnValue;
      }
  
      public HashMap&lt;String, String&gt; getResult() {
          return result;
      }
  
      public void setResult(HashMap&lt;String, String&gt; result) {
          this.result = result;
      }
  
      public Object[] getResultList() {
          return resultList;
      }
  
      public void setResultList(Object[] resultList) {
          this.resultList = resultList;
      }
  }
  </code></pre>
  
  <p>And this is my compute logic</p>
  
  <pre><code>/**
   * This method gets the current input and returns list with all suitable cities
   * @return
   */
  public static HashMap autocomplete(String input) {
  
      // Initialize the variable
      HashMap&lt;String, String&gt; result = null;
  
      // The url connection will be used
      HttpURLConnection conn = null;
  
      // String builder for the json results
      StringBuilder jsonResults = new StringBuilder();
      try {
          // Build the string for the url
          StringBuilder sb = new StringBuilder(PLACES_API_BASE + TYPE_AUTOCOMPLETE + OUT_JSON);
          sb.append("?key=" + API_KEY);
  
          // This parameter is used for choosing specific country, not must.
          sb.append("&amp;input=" + URLEncoder.encode(input, "utf8"));
  
  
    // Create the url
      URL url = new URL(sb.toString());
      conn = (HttpURLConnection) url.openConnection();
      InputStreamReader in = new InputStreamReader(conn.getInputStream());
  
      // Load the results into a StringBuilder
      int read;
      char[] buff = new char[1024];
      while ((read = in.read(buff)) != -1) {
          jsonResults.append(buff, 0, read);
      }
  } catch (MalformedURLException e) {
      Log.e(LOG_TAG, "Error processing Places API URL", e);
      return result;
  } catch (IOException e) {
      Log.e(LOG_TAG, "Error connecting to Places API", e);
      return result;
  } finally {
      if (conn != null) {
          conn.disconnect();
      }
  }
  
  try {
      // Create a JSON object hierarchy from the results
      JSONObject jsonObj = new JSONObject(jsonResults.toString());
      JSONArray predsJsonArray = jsonObj.getJSONArray("predictions");
  
      // Extract the Place descriptions from the results
      result = new HashMap&lt;&gt;(predsJsonArray.length());
      for (int i = 0; i &lt; predsJsonArray.length(); i++) {
          result.put(predsJsonArray.getJSONObject(i).getString("description"),
                     predsJsonArray.getJSONObject(i).getString("place_id"));
      }
  } catch (JSONException e) {
      Log.e(LOG_TAG, "Cannot process JSON results", e);
  }
  
  return result;
  </code></pre>
  
  <p>}</p>
  
  <p>Does anyone has an idea whats wrong? what to take card of?</p>
  
  <p>Thanks a lot in advance,
  Eden</p>