gpt4 book ai didi

java - Android onPostExecute 未被识别

转载 作者:行者123 更新时间:2023-12-01 22:00:26 25 4
gpt4 key购买 nike

这是我的代码:

//.___ Async task bring info from API __./
AsyncTask asyncTask = new AsyncTask() {
@Override
protected Object doInBackground(Object[] objects) {
mMovieDto = mDataSource.getPopularMovies();
return null;
}

@Override
protected void onPostExecute(Long result) {
fillList();
}
};
asyncTask.execute();

我收到以下错误:onPostExecute 未从 super 重写,女巫是将这个方法之王添加到我的 AsyncTask 的正确方法吗?

感谢您的帮助何塞

最佳答案

您缺少 AsyncTask 的泛型类型:

The three types used by an asynchronous task are the following:

  1. Params, the type of the parameters sent to the task upon execution.
  2. Progress, the type of the progress units published during the background computation.
  3. Result, the type of the result of the background computation.

Not all types are always used by an asynchronous task. To mark a type as unused, simply use the type Void:

private class MyTask extends AsyncTask<Void, Void, Void> { ... }

像这样更改您的代码:

AsyncTask asyncTask = new AsyncTask<Void, Void, Void>() {

@Override
protected Void doInBackground(Void... params) {
mMovieDto = mDataSource.getPopularMovies();
return null;
}

@Override
protected void onPostExecute(Void result) {
fillList();
}
};
asyncTask.execute();

关于java - Android onPostExecute 未被识别,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/33614645/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com