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

Why do I get an error when declaring this class "private"?

I'm working on the Web Posts Blog track, and am having problems with the declaration of the GetBlogPostsTask. I am pretty sure that I have followed the steps as they were given in the videos, but I am getting an error at this declaration: (I am also using Android Studio as opposed to the Eclipse IDE which is used in the video.

" private class GetBlogPostsTask extends AsyncTask<Object, Void, String> { "

The error is shown to be on the keyword "private" and is says "Modifier 'private' not allowed here". As a result, the type "GetBlogPoststype" is not recognized in the main part of the code where it is used.

Any ideas?

3 Answers

Just figure out my problem Stupid me! I was using a "{" where I should have been using a "(", thus closing off a class definition prematurely. Changed the symbols and it worked just fine.

(It's hard to see these tiny symbols when your vision is going!).

Sorry for the odd post, but thank you for your reply, Jaroslav!

No idea this works in my code, try adding the specification of the generic AsyncTask (if you didn't) - Object, Void and JSONObject. So the code would look like this:

private class GetBlogPostsTask extends AsyncTask<Object,Void,JSONObject> {
/*****your code*****/
}
private class CustomAsyncTask extends AsyncTask<Object, Void, String> {
    @Override
    protected String doInBackground(Object ... params){
        return ""; //here we return an empty String
    }
}