Take the 2-minute tour ×

First off, let me explain that I am well aware of what this exception means, please read the question thoroughly if you're going to answer.

I know that the exception arises when you try to do UI work on a network thread. I am using AsyncTask but I'm doing any UI operations.

Here is the snippet from AsyncTask code where the error is being thrown NOTE aps and adm are declared ahead of time Its in the Extracter initialization that the exception is being thrown:


                HttpPost request = new HttpPost(params[0]);
                request.setHeader("Accept", "application/json");
                request.setHeader("Content-type", "application/json");
                StringEntity filterEntity = new StringEntity(aps.TempParameter()); //Remember this TempParameter is temporary function
                response = httpClient.execute(request);
                StatusLine statusLine = response.getStatusLine();
                if(statusLine.getStatusCode() == HttpStatus.SC_OK){
                    Extracter extracter = new Extracter(response);
                    lastSent = extracter.extractLastSent();
            } catch (ClientProtocolException e) {
                //TODO Handle problems..
                builder.append("Client protocol exception");
            } catch (IOException e) {
                //TODO Handle problems..
        }while(lastSent != "done");

            return adm.getAlarmObjectList();

The line

    Extracter extracter = new Extracter(response);

is where the exception is thrown. Here is the code for the Extracter class:

    public class Extracter extends AlarmLoopTestActivity {

private JSONObject jo;
private JSONArray ja;

public Extracter(HttpResponse response){
    StringBuilder builder = new StringBuilder();
    HttpEntity entity = response.getEntity();
    try {
        InputStream content = entity.getContent();
        String line;
    } catch (IllegalStateException e) {
        // TODO Auto-generated catch block
    } catch (IOException e) {
        // TODO Auto-generated catch block
    String json = builder.toString();
    try {
        jo = (JSONObject) new JSONTokener(json).nextValue();
        ja = jo.getJSONArray("effectNamesDict");
    } catch (JSONException e) {
        jo = null;


I'm assuming printingStackTrace is not considered a UI event. Other then that, I'm at a loss. I need to get new eyes on this. Let me know if I need to elaborate anything further.

share|improve this question
What is AlarmLoopTestActivity? In other words, what does it extend originally? –  Squonk May 18 '12 at 23:08
That might be it, its not supposed to extend that. –  SmashCode May 18 '12 at 23:10
But to answer your question, AlarmLoopTestActivity is the main Activity, NOT the worker thread, I'm fixing it right now, and I bet thats it. I can't believe I didn't notice that. –  SmashCode May 18 '12 at 23:12
add comment

1 Answer

up vote 0 down vote accepted

Your Extracter is extending a class AlarmLoopTestActivity going from the name this is an android Activity and so it probably has some UI interaction methods in there!

share|improve this answer
The UI interaction isn't the problem. Trying to create an instance of an Activity using new is a major problem. As the OP has pointed out in the comments, it's not supposed to be extending that class anyway. –  Squonk May 18 '12 at 23:21
@MisterSquonk Yes so thats his problem that the Activity was being created on a non-ui thread –  Blundell May 18 '12 at 23:37
add comment

Your Answer


