Welcome to the Treehouse Community

Want to collaborate on code errors? Have bugs you need feedback on? Looking for an extra set of eyes on your latest project? Get support with fellow developers, designers, and programmers of all backgrounds and skill levels here with the Treehouse Community! While you're at it, check out some resources Treehouse students have shared here.

Looking to learn something new?

Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and join thousands of Treehouse students and alumni in the community today.

Start your free trial

Android Build a Blog Reader Android App Adapting Data for Display in a List Finishing Our AsyncTask

I am getting repeated error for this onPostExecute assignment?

import android.os.AsyncTask;
import android.os.Bundle;

public class CustomActivity extends Activity {

    public String mStatus;

    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_custom);
        CustomAsyncTask task = new CustomAsyncTask();
        task.execute();
    }

    protected void updateStatusLabel() {
        super.updateStatusLabel();
    }

    protected class CustomAsyncTask extends AsyncTask<Object, Void, JSONObject> {   
        @Override
        protected JSONObject doInBackground(Object... params) {
            // Imagine this is some code to do some work
            JSONObject jsonResponse = null;
                       return jsonResponse;
        }
    @Override
        protected void onPostExecute(JSONObject result) {

        }


    }
}

I have added the onPostExecute and made changes from String to JSONObject. Still it doesnt work ?

CustomActivity.java
import android.os.AsyncTask;
import android.os.Bundle;

public class CustomActivity extends Activity {

    public String mStatus;

    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_custom);
        CustomAsyncTask task = new CustomAsyncTask();
        task.execute();
    }

    protected void updateStatusLabel() {
        super.updateStatusLabel();
    }

    protected class CustomAsyncTask extends AsyncTask<Object, Void, JSONObject> {   
        @Override
        protected JSONObject doInBackground(Object... params) {
            // Imagine this is some code to do some work
            JSONObject jsonResponse = null;
      return jsonResponse;
        }
    @Override
        protected void onPostExecute(JSONObject result) {

        }


    }
}

What error are you getting exactly?

1 Answer

./CustomActivity.java:20: error: cannot find symbol protected class CustomAsyncTask extends AsyncTask { ^ symbol: class JSONObject location: class CustomActivity ./CustomActivity.java:22: error: cannot find symbol protected JSONObject doInBackground(Object... params) { ^ symbol: class JSONObject location: class CustomActivity.CustomAsyncTask ./CustomActivity.java:28: error: cannot find symbol protected void onPostExecute(JSONObject result) { ^ symbol: class JSONObject location: class CustomActivity.CustomAsyncTask ./CustomActivity.java:24: error: cannot find symbol JSONObject jsonResponse = null; ^ symbol: class JSONObject location: class CustomActivity.CustomAsyncTask 4 errors