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

Help with Code Challenge: Moving Work from the Main Thread to an AsyncTask.

Create a private class inside MainListActivity named 'CustomAsyncTask' and have it extend AsyncTask. Don't put anything in it yet, but AsyncTask requires 3 generic types: use 'Object', 'Void', and 'String'. Hint: The format will be AsyncTask<type1, type2, type3>.

I am getting java errors for not having my curlybrackets in the right places and for my private class being an illegal start of expression. I'm not sure if I'm making this more difficult than it needs to be, but some guidance would help me a lot.

` package com.example;

import android.os.Bundle; import android.view.View; import java.io.IOException; import java.net.MalformedURLException; import android.util.Log; import android.os.AsyncTask;

public class MainListActivity extends ListActivity {

public static final String URL = "http://www.teamtreehouse.com";
public static final String TAG = MainListActivity.class.getSimpleName();

@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); 
    }

     private class CustomAsyncTask extends AsyncTask<Object, Void, String>{

}

} `

1 Answer

David Kaneshiro Jr.
David Kaneshiro Jr.
29,247 Points

Hi Ginger Ranslam

It looks like all you're missing is a closing curly brace '}' for your private class AsyncTask. I copied your code and added the missing curly brace and the challenge passed.

private class CustomAsyncTask extends AsyncTask<Object, Void, String>{
}

I finally did it. The problem was I was putting that line of code in the wrong spot and needed to do it after the second to last curly brace. Thanks for the help though!