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 Getting Data from the Web Moving Work from the Main Thread to an AsyncTask

Getting Data from the Web - Task 2

I am not sure why my code isn't working. May I request assistance?

public class MainListActivity extends ListActivity {

    public static final String URL = "http://www.teamtreehouse.com";
    public static final String TAG = MainListActivity.class.getSimpleName();
    private class CustomAsyncTask extends AsyncTask{
      @Override
    protected String doInBackground (Object... arg0)
    }

    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main_list);

        try {
            URL treehouseUrl = new URL(URL);
            HttpURLConnection connection = (HttpURLConnection) treehouseUrl.openConnection();
            connection.connect();
            int responseCode = connection.getResponseCode();
        }
        catch (MalformedURLException e) {
            Log.e(TAG, "MalformedURLException caught!", e);
        }
        catch (IOException e) {
            Log.e(TAG, "IOException caught!", e);
        }
      return ""
    }
}

1 Answer

Ben Jakuben
STAFF
Ben Jakuben
Treehouse Teacher

You don't need the return statement at the bottom because onCreate() is a void method (meaning it doesn't return anything).

Then you need to add a new class after onCreate() but before the closing brace of the MainListActivity class. Here's a hint to get you started:

private class CustomAsyncTask ...