Android Force Close (ConcurrentModificationException)
<p>I keep getting this error and I'm thinking it's because I am using so many AsyncTask's. I have a list and in my onclick listener I use one to upload a view to my database (to keep track of how many times songs have been viewed) and I also have one to check to see if a song has been favorited by the user.</p>

<p>Here is what the LogCat says:</p>

<pre><code>02-18 15:46:18.986: E/log_tag(282): Error in http connectionjava.util.ConcurrentModificationException
02-18 15:46:19.016: E/log_tag(282): Error converting result java.lang.NullPointerException
02-18 15:46:19.376: W/dalvikvm(282): threadid=12: thread exiting with uncaught exception (group=0x4001d800)
02-18 15:46:20.696: E/AndroidRuntime(282): FATAL EXCEPTION: AsyncTask #5
02-18 15:46:20.696: E/AndroidRuntime(282): java.lang.RuntimeException: An error occured while executing doInBackground()
02-18 15:46:20.696: E/AndroidRuntime(282):  at android.os.AsyncTask$3.done(AsyncTask.java:200)
02-18 15:46:20.696: E/AndroidRuntime(282):  at java.util.concurrent.FutureTask$Sync.innerSetException(FutureTask.java:273)
02-18 15:46:20.696: E/AndroidRuntime(282):  at java.util.concurrent.FutureTask.setException(FutureTask.java:124)
02-18 15:46:20.696: E/AndroidRuntime(282):  at java.util.concurrent.FutureTask$Sync.innerRun(FutureTask.java:307)
02-18 15:46:20.696: E/AndroidRuntime(282):  at java.util.concurrent.FutureTask.run(FutureTask.java:137)
02-18 15:46:20.696: E/AndroidRuntime(282):  at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1068)
02-18 15:46:20.696: E/AndroidRuntime(282):  at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:561)
02-18 15:46:20.696: E/AndroidRuntime(282):  at java.lang.Thread.run(Thread.java:1096)
02-18 15:46:20.696: E/AndroidRuntime(282): Caused by: java.lang.NullPointerException
02-18 15:46:20.696: E/AndroidRuntime(282):  at org.json.JSONTokener.nextCleanInternal(JSONTokener.java:112)
02-18 15:46:20.696: E/AndroidRuntime(282):  at org.json.JSONTokener.nextValue(JSONTokener.java:90)
02-18 15:46:20.696: E/AndroidRuntime(282):  at org.json.JSONArray.&lt;init&gt;(JSONArray.java:87)
02-18 15:46:20.696: E/AndroidRuntime(282):  at org.json.JSONArray.&lt;init&gt;(JSONArray.java:103)
02-18 15:46:20.696: E/AndroidRuntime(282):  at com.appinfluence.musicpromotion.SongList$CheckFavorite.doInBackground(SongList.java:991)
02-18 15:46:20.696: E/AndroidRuntime(282):  at com.appinfluence.musicpromotion.SongList$CheckFavorite.doInBackground(SongList.java:1)
02-18 15:46:20.696: E/AndroidRuntime(282):  at android.os.AsyncTask$2.call(AsyncTask.java:185)
02-18 15:46:20.696: E/AndroidRuntime(282):  at java.util.concurrent.FutureTask$Sync.innerRun(FutureTask.java:305)
02-18 15:46:20.696: E/AndroidRuntime(282):  ... 4 more
</code></pre>

<p>Here is an example of me checking for a favorite:</p>

<pre><code>private class CheckFavorite extends AsyncTask&lt;String, UserRecord, JSONArray&gt; {

    InputStream is2 = null;
    JSONArray jArray2;
    StringBuilder sb2 = null;
    String resulttt = null;


    protected JSONArray doInBackground(String... link) {

        URI uri = null;
        try {
            uri = new URI(link[0]);
        } catch (URISyntaxException e2) {
            // TODO Auto-generated catch block
            e2.printStackTrace();
        }

        //http post
        try{
            HttpClient httpclient = new DefaultHttpClient();
            HttpPost httppost = new HttpPost(uri);
            httppost.setEntity(new UrlEncodedFormEntity(nameValuePairs2));
            HttpResponse response = httpclient.execute(httppost);
            HttpEntity entity = response.getEntity();
            is2 = entity.getContent();
        }catch(Exception e){
            Log.e("log_tag", "Error in http connection"+e.toString());
        }   

        //convert response to string
        try{
            BufferedReader reader = new BufferedReader(new InputStreamReader(is2,"UTF8"),8);
            sb2 = new StringBuilder();
            sb2.append(reader.readLine() + "\n");

            String line="0";
            while ((line = reader.readLine()) != null) {
                sb2.append(line + "\n");
            }
            is2.close();
            resulttt=sb2.toString();
        }catch(Exception e){
            Log.e("log_tag", "Error converting result "+e.toString());
        }

        try{
            jArray2 = new JSONArray(resulttt);
            JSONObject json_data=null;

            favresult = new int[jArray2.length()];  

            for(int i=0;i&lt;jArray2.length();i++){
                json_data = jArray2.getJSONObject(i);
                favresult[0]=json_data.getInt("counter");
            }
        }
        catch(JSONException e1){
            e1.printStackTrace();

        } catch (ParseException e1) {
            e1.printStackTrace();
        }           

        return null;
    }

    protected void onProgressUpdate(UserRecord... progress) {           
    }

    protected void onPostExecute(JSONArray jArray) {    
        if (favresult[0] &gt; 0){
            favoritesbutton.setText("Remove from Favorites");
            favprogress.setVisibility(View.GONE);

        } else {
            favoritesbutton.setText("Add to Favorites");
            favprogress.setVisibility(View.GONE);

        }

        //new LoadView().execute(viewsphp);


    }

    protected void onPreExecute(){
        favprogress.setVisibility(View.VISIBLE);
        favoritesbutton.setText("");
        favprogress.setVisibility(View.VISIBLE);

    }
}
</code></pre>

<p>How might I avoid a force close like this? If you need any other information please tell me, I will provide anything to help get to the bottom of this. Thanks!</p>
