Skip to content Skip to sidebar Skip to footer

The Return Type Is Incompatible With Asynctask

I'm trying to capture the response of httpclient using AsyncTask but throws me the following error verifying any incompatibility doInBackground in the String: 'the return type is

Solution 1:

the problem here is that AsyncTask Extensions are generic and need three types: AsyncTask<Params, Progress, Result>AsyncTask which may be Void or a class, but not primitive data types.

so what happens is you told the compiler that doInBackground returns a primitive var but it was expecting an instance of the class String.

So use doInBackground function as

@Override
            protected String doInBackground(String... params) {
                // TODO Auto-generated method stub


                String result = insertar();

                return result;
            }

Edit

In AsyncTask you are returning Boolean and in doInBackground return type is String,so

change it to String because you want String value from insertar() function,i.e. change

class Insertar extends AsyncTask<String,String,Boolean>{

to

class Insertar extends AsyncTask<String,String,String>{

and

 @Override
        protected void onPostExecute(Boolean result) {

        }

to

 @Override
        protected void onPostExecute(String result) {

        }

Post a Comment for "The Return Type Is Incompatible With Asynctask"