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

Matej Marjanovic
Matej Marjanovic
7,762 Points

Getting "incompatible types" error with but don't know what's wrong.

This is from "Build a Blog Reader Android App", step 6, task 2 from "Getting Data from the Web".

This is my attempt at the solution:

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

@Override
protected String doInBackground(Object... params){
  String emptyStr = "";
  return emptyStr;
}

}

Originally I tried just returning the empty string directly but that gives the same error which is:

./com/example/MainListActivity.java:17: incompatible types found : java.lang.String required: String String emptyStr = ""; ^ 1 error

1 Answer

Gergő Bogdán
Gergő Bogdán
6,664 Points

I think the compiler error message is a little bit misleading.

The

AsyncTask

class is a generic class, which means you have to specify some addition type information to it, so it knows what type of data will be returned.

//your class definitions
class CustomAsyncTask extends AsyncTask {
//...
}

//what should be
class CustomAsyncTask extends AsyncTask <Object, Void, String>{
///....
}

From

AsyncTask<Object, Void, String>

it knows that the return value of the method should String.