gpt4 book ai didi

java - 未经检查的调用 'execute(Params...)' 作为原始类型 'android.os.AsyncTask' 的成员

转载 作者:IT老高 更新时间:2023-10-28 20:46:39 29 4
gpt4 key购买 nike

我正在关注 Udacity 上的 google android 教程,但在指定的代码中,我收到以下警告:

Unchecked Call to 'execute(Params...)' as a member of raw type 'android.os.AsyncTask'

关于此代码:

DoSomethingTask myTask = new DoSomethingTask();
myTask.execute(); // Warning here

DoSomethingTask:

public class DoSomethingTask extends AsyncTask {

protected Object doInBackground(Object[] params) {
...
}
}

谁能解释这个警告以及如何解决它?看来它应该按照说明工作......

最佳答案

警告是由任务的参数引起的。尝试使用:

extends AsyncTask<Void, Void, Void>{
protected Object doInBackground() {
}
}

或使用:

extends AsyncTask<Object, Void, Void>{
protected Object doInBackground(Object[] params) {
}
}
myTask.execute(anyObject);

解释:

This文档解释了 AsyncTask 的三种类型的含义。

  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.

关于java - 未经检查的调用 'execute(Params...)' 作为原始类型 'android.os.AsyncTask' 的成员,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/29998075/

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