无法覆盖 AsyncTask 类中的 onPostExecute() 方法或使其触发 [英] Can't Override onPostExecute() method in AsyncTask Class or get it to trigger

查看:19
本文介绍了无法覆盖 AsyncTask 类中的 onPostExecute() 方法或使其触发的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在运行 AsyncTask 时无法调用 onPostExecute() 方法.当我尝试设置扩展 AsyncTask 的类时,其中 onPostExecute() 被覆盖,我收到以下构建错误.

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.

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

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

我尝试去掉 @Override 注释.这消除了构建错误,但该方法仍然没有执行.如果有人愿意指出我所忽略的内容,我将不胜感激.

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.

代码:

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() 接受一个参数(你从 doInBackground() 返回的对象).将其更改为 protected void onPostExecute(Void v).如果您不提供参数,方法签名将不匹配,并且覆盖注释开始抱怨没有使用此签名覆盖的函数.

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.

这篇关于无法覆盖 AsyncTask 类中的 onPostExecute() 方法或使其触发的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆