Organizational Research By

Surprising Reserch Topic

boostr.in questions - Question:Fatal Spin-On-Suspend/Stuck on ThreadID


I'm creating a custom calendar for an Android app. The way it works now is that it pulls events from an online MySQL database, transfers them into a JSONArray, and inputs them into the calendar from there. It was working fine (if a bit slow) on an emulator, but today I hooked up my S3 and it's giving me errors that I haven't received before. The errors I'm getting in my log say:

09-14 22:52:12.611: E/dalvikvm(4605): threadid=2: stuck on threadid=1, giving up

09-14 22:52:12.611: E/dalvikvm(4605): Fatal spin-on-suspend, dumping threads

This is the ASyncTask that it keeps getting hung up on:

package com.legends.app;

import java.io.BufferedReader;
import java.io.InputStream;
import java.io.InputStreamReader;

import org.apache.http.HttpEntity;
import org.apache.http.HttpResponse;
import org.apache.http.client.HttpClient;
import org.apache.http.client.methods.HttpPost;
import org.apache.http.impl.client.DefaultHttpClient;
import org.json.JSONArray;
import android.os.AsyncTask;
import android.util.Log;

public class Events extends AsyncTask {

    JSONArray jArray;
    public String result = null;
    InputStream is = null;
    StringBuilder sb=null;
    HttpEntity entity;

    protected String doInBackground(Void... arg0) {

          //http post - calls from the php file that opens the DB
          try{

               HttpClient httpclient = new DefaultHttpClient();
               HttpPost httppost = new HttpPost("http://legendsofnotredame.org/club/mobile/android/cal.php");
               HttpResponse response = httpclient.execute(httppost);

               entity = response.getEntity();

               }catch(Exception e){
                   Log.e("log_tag", "Error in http connection"+e.toString());
              }

          //convert response to string
            try{

                is = entity.getContent();

                BufferedReader reader = new BufferedReader(new InputStreamReader(is,"iso-8859-1"),8);

                 sb = new StringBuilder();

                 sb.append(reader.readLine() + "\n");                 

                 String line="0";
                 while ((line = reader.readLine()) != null) {
                                sb.append(line + "\n");
                  }
                  is.close();
                  result=sb.toString();
                  }catch(Exception e){
                        Log.e("log_tag", "Error converting result "+e.toString());
                  }
            Log.e("test","Converted results to string");
            return result;
    }

    protected void onPostExecute(String result) {

    }

}

After adding a ton of logs, I determined that it was getting hung up on "sb.append(reader.readLine() + "\n");", and I'm not sure how to make it not do that. Any tips?

Edit: Here's the (almost) full logcat for running it, starting from where it hangs on readLine. I had to cute out some non-warning/non-error lines at the beginning because this post is too long, sorry!

And here's where I call it in the main Activity. These are also two separate files, I don't know if that's relevant but it might be, I don't know.

 Events db = new Events();
        db.execute();
        while (db.result == null){
         continue;}
        result = db.result;
asked Sep 13, 2013 in Java Interview Questions by anonymous
edited Sep 12, 2013
0 votes
62 views



Related Hot Questions



Government Jobs Opening


...