不能覆盖onPostExecute()方法中的AsyncTask类或得到它的触发它的、方法、onPostExecute、AsyncTask

2023-09-04 12:20:25 作者:抢我女神死的早i

我无法运行时,一个的AsyncTask 获得 onPostExecute()方法来调用。当我尝试建立我的延长的AsyncTask 类,其中 onPostExecute()被重写,我得到了下面的生成错误

  

的方法onPostExecute类型AsyncTaskExampleActivity的()必须   覆盖或实现超类型的方法

我试图摆脱 @覆盖注释。这摆脱了生成错误的,但该方法仍不能执行。如果任何一个人会这么好心地指出什么我俯瞰,我将不胜AP preciated吧。

code:

 包com.asynctaskexample;

进口android.os.AsyncTask;

公共类AsyncTaskExampleActivity扩展的AsyncTask<虚空,虚空,虚空> {

AsyncTaskExampleActivity(){
超();
    }

@覆盖
在preExecute保护无效(){
    }

@覆盖
保护无效doInBackground(虚空...... PARAMS){
    返回null;
}

@覆盖
保护无效onPostExecute(){
    }
}
 

解决方案

OnPostExecute()带有参数的(从返回对象doInBackground())的。将其更改为保护无效onPostExecute(虚空V)。如果不提供参数,该方法签名不匹配,并且覆盖注释开始抱怨没有功能重写与此签名。

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.

Android消息机制 异步任务AsyncTask

'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() {
    }
}

解决方案

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.