扩展 Asynctask 的 class 的执行函数采用可变参数,但是当我将一个参数传递给该函数时出现错误
The execute function of class that extends Asynctask takes varargs, but I'm getting an error when I pass one parameter to the function
我正在 eclipse 中开发一个 android 应用程序,这就是我在主程序中调用的 activity:
new PhotoUpdate(app).execute(Pair.create(PhotoUpdate.PARAM_FILE, photoPath));
我的 AsyncTask class 看起来像这样:
public class PhotoUpdate extends AsyncTask<Pair<String, String>, Void, String> {
//some code
@Override
protected String doInBackground(Pair<String, String>...params) {
//delegate functionality to some other methods
}
}
但是,在我的 activity 中,我在调用 execute 时遇到一个编译器错误,上面写着:
The method execute(Pair<String,String>...) in the type
AsyncTask <Pair<String,String>,Void,String> is not applicable for the arguments
(Pair<String,String>)
这些是它提供的快速修复:
本质上是在抱怨我不能将一对字符串传递给一个需要多对字符串的函数,这没有意义。有没有其他人看到这个错误?
问题已解决!
我在我的项目中使用了一个支持库,PhotoUpate
Class 中的 Pair 对象和我用来调用 execute 的 Pair 对象来自不同的库(一个来自支持库来自 android 图书馆)。
'Pair...' 这意味着您将必须发送一个 'pair' 的数组,并且您将使用参数 [0] 在 doinbackground 上获取数据,您可以使用构造函数来代替会更好。
我正在 eclipse 中开发一个 android 应用程序,这就是我在主程序中调用的 activity:
new PhotoUpdate(app).execute(Pair.create(PhotoUpdate.PARAM_FILE, photoPath));
我的 AsyncTask class 看起来像这样:
public class PhotoUpdate extends AsyncTask<Pair<String, String>, Void, String> {
//some code
@Override
protected String doInBackground(Pair<String, String>...params) {
//delegate functionality to some other methods
}
}
但是,在我的 activity 中,我在调用 execute 时遇到一个编译器错误,上面写着:
The method execute(Pair<String,String>...) in the type
AsyncTask <Pair<String,String>,Void,String> is not applicable for the arguments
(Pair<String,String>)
这些是它提供的快速修复:
本质上是在抱怨我不能将一对字符串传递给一个需要多对字符串的函数,这没有意义。有没有其他人看到这个错误?
问题已解决!
我在我的项目中使用了一个支持库,PhotoUpate
Class 中的 Pair 对象和我用来调用 execute 的 Pair 对象来自不同的库(一个来自支持库来自 android 图书馆)。
'Pair...' 这意味着您将必须发送一个 'pair' 的数组,并且您将使用参数 [0] 在 doinbackground 上获取数据,您可以使用构造函数来代替会更好。