46

I am having trouble getting the onPostExecute() method to call when running an AsyncTask. When I try to set up my class extending AsyncTask in which the onPostExecute() is overridden I get the following build error.

'The method onPostExecute() of type AsyncTaskExampleActivity must override or implement a supertype method'

I have tried getting rid of the @Override annotation. This gets rid of the build error but the method still does not execute. If any one would be so kind as to point out what I'm overlooking I would greatly appreciated it.

Code:

package com.asynctaskexample;

import android.os.AsyncTask;

public class AsyncTaskExampleActivity extends AsyncTask<Void, Void, Void> {

AsyncTaskExampleActivity(){
super();
    }

@Override
protected void onPreExecute() {
    }

@Override
protected Void doInBackground(Void... params) {
    return null;
}

@Override
protected void onPostExecute() {
    }
}
Ben
  • 515
  • 1
  • 6
  • 9

4 Answers4

108

OnPostExecute() takes an argument (the object you return from doInBackground()). Change it to protected void onPostExecute(Void v). If you don't provide the argument, the method signatures do not match and the override annotation starts to complain that there is no function to override with this signature.

24

Try:

In the class try right click Source -> Override/Implement methods.. and look for the onPostExecute() method. It will give you complete method with all types of arguments should it get.

Nikola Despotoski
  • 49,966
  • 15
  • 119
  • 148
0

if you want your onPostExecute() to be overitten, simply use what was returned in your doInBackground() as an object in your onPostExecute().

For example...

    @Override
    protected void doInBackground(Void...args0){
        // your code here...
        return value;
    }
    @Override
    protected void onPostExecute(void value){
        //code to run
    }
-1

You should add super.onPostExecute() method. For example:

@Override
protected void onPostExecute(Void nothing)
{
   super.onPostExecute(nothing);
}

EDIT: Guys, I have no idea why you are downvoting the answer. The questioner is missing an argument of onPostExecute() method and doesn't have a supertype method implemented. Thats's the reason I posted this answer.

Ayaz Alifov
  • 8,334
  • 4
  • 61
  • 56