title: Why I get java.util.ConcurrentModificationException error?
body: <p>I'm having troubles with this code:</p>
  
  <pre><code>protected void onPostExecute(ArrayList&lt;Example&gt; examples){
          for(Example i : examples)
          {
              customAdapter.add(i);
          }
          listExamples.setAdapter(customAdapter);
      }
  </code></pre>
  
  <p>where listExamples it's a <code>ListView</code> that I have in my mainActivity layout.</p>
  
  <p>The error that it gives to me it's the <code>java.util.ConcurrentModificationException</code> error. I know that it happens when you modify, for example, an ArrayList inside the loop but here I don't really modify my ArrayList of values. I just add the objects of <code>Example</code> into my CustomAdapter (which is not iterating in the loop).</p>
  
  <p>Note: As you can see, this code it's wrap in the onPostExecute part of my <code>AsynkTask</code> method.</p>
  
  <p>I look on the Internet questions and here in Stackoverflow but I coudn't solve my problem. In all the questions that I have seen I see that they have an ArrayList that they are modifying inside the loop, but it is not my case.</p>
  
  <p>If any of you have idea about how to solve it or if I'm wrong with the concepts that I put above please let me know.</p>
  
  <p>Thanks in advance!</p>
  
  <p><strong>EDIT:</strong> The stack trace of my log console (I simplified it by post only the Error logs)</p>
  
  <pre><code>06-05 02:22:31.891  24678-24678/ccom.example.user.project E/﹕ appName=com.example.user.project, acAppName=/system/bin/surfaceflinger
  06-05 02:22:31.891  24678-24678/com.example.user.project E/﹕ 0
  06-05 02:22:31.891  24678-24678/com.example.user.project E/﹕ appName=com.example.user.project, acAppName=/system/bin/surfaceflinger
  06-05 02:22:31.891  24678-24678/com.example.user.project E/﹕ 0
  06-05 02:22:32.953  24678-24678/com.example.user.project E/AndroidRuntime﹕ FATAL EXCEPTION: main
      Process: com.example.user.project, PID: 24678
      java.util.ConcurrentModificationException
              at java.util.ArrayList$ArrayListIterator.next(ArrayList.java:573)
              at com.example.user.project.MainActivity$chargeExample.onPostExecute(MainActivity.java:192)
              at com.example.user.project.MainActivity$chargeExample.onPostExecute(MainActivity.java:131)
              at android.os.AsyncTask.finish(AsyncTask.java:632)
              at android.os.AsyncTask.access$600(AsyncTask.java:177)
              at android.os.AsyncTask$InternalHandler.handleMessage(AsyncTask.java:645)
              at android.os.Handler.dispatchMessage(Handler.java:110)
              at android.os.Looper.loop(Looper.java:193)
              at android.app.ActivityThread.main(ActivityThread.java:5333)
              at java.lang.reflect.Method.invokeNative(Native Method)
              at java.lang.reflect.Method.invoke(Method.java:515)
              at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:828)
              at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:644)
              at dalvik.system.NativeStart.main(Native Method)
  </code></pre>
  
  <p><strong>EDIT 2:</strong> Here is my <code>asynktask</code> method and the code in <code>doInBackground()</code></p>
  
  <pre><code>class chargeExample extends AsyncTask&lt;Void, Integer, ArrayList&lt;Example&gt;&gt; {
          protected void onPreExecute(){
          }
          protected ArrayList&lt;Example&gt; doInBackground(Void... params) {
  
              String url = "url of my GET method of my API REST";
  
              HttpGet method = new HttpGet(url);
  
              method.setHeader("content-type", "application/json");
  
              try{
                  HttpResponse response = httpClient.execute(method);
                  String responseString = EntityUtils.toString(response.getEntity());
                  JSONArray responseJSON = new JSONArray(responseString);
                  for(int i=0; i&lt;responseJSON.length(); i++){
                      JSONObject object = responseJSON.getJSONObject(i);
  
                      int idMain = object.getInt("idMain");
                      String date = object.getString("date");
                      String name = object.getString("name");
                      double value = object.getDouble("value");
                      SimpleDateFormat sdf = new SimpleDateFormat("yyyy-M-dd");
                      Date datePar = sdf.parse(date);
  
                      examp.add(new Example(idMain, datePar, name, value));
                  }
              }catch(Exception ex){
                  Log.e("ServicioRest", ex.toString());
              }
              return examp;
          }
  </code></pre>