Solve remove @Override annotated problem in AsyncTask onPostExecute() Android


Here are some example code that may produce error on onPostExecute() in AsyncTask and need to remote @Override annotation :

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
class queriesTask extends AsyncTask<Object, Void, Object> {
    @Override
    protected Object[] doInBackground(Object… params) {
        Object[] result = new Object[5];
        try {
            result[0] = SearchRequest((String) params[0]);             
        } catch (Exception e) {
            result[0] = null;              
        }
       
        result[1] = params[1];
        result[2] = params[2];
        result[3] = params[3];
        result[4] = params[4];
       
        return result;
       
    }
   
    @Override
    protected void onPostExecute(Object[] result) {
        ProcessResponse((String) result[0],
                (List<String>)result[1], (List<String>)result[2],
                (Bitmap[])result[3], (boolean[])result[3]);
    }
   
}


This will generate errors :

1
The method onPostExecute(Object[]) of type Main.queriesTask must override or implement a supertype method

Which need to remove @Override in onPostExecute() in AsyncTask.

How to solve this problem ?

Actually, it’s definitely simple!

Watch at this line :

1
class queriesTask extends AsyncTask<Object, Void, Object> {

And looks at this line :

1
2
@Override
protected void onPostExecute(Object[] result) {

See what’s wrong here ? Yes, it because onPostExecute have different type with AsyncTask().
You should have same type in AsyncTask(DoInBackground, Progress, OnPostExecute) with their implement methods.

Solution is by rename Object into Object[] in AsyncTask().

1
class queriesTask extends AsyncTask<Object, Void, Object> {

Into :

1
class queriesTask extends AsyncTask<Object, Void, Object[]> {

Sometimes we need to take rest and a cup of cofee 🙂


Leave a Reply

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.