gpt4 book ai didi

android - 错误 : method execute in class AsyncTask 无法应用于给定类型

转载 作者:可可西里 更新时间:2023-11-01 08:26:43 25 4
gpt4 key购买 nike

我想通过 php 将文本和图像从 android 发送到 MySQL。但是,我收到错误并且无法解决。有人可以帮我解决问题吗?非常感谢

添加函数

 public void Add(final String claimType, final String Amount, final String Description,  final Bitmap photo)
{
class AddImage extends AsyncTask<Void, Void, String> {
ProgressDialog loading;

@Override
protected void onPreExecute() {
super.onPreExecute();
loading = ProgressDialog.show(getApplicationContext(), "Please Wait",null, true, true);
}

@Override
protected void onPostExecute(String s) {
super.onPostExecute(s);
loading.dismiss();
Toast.makeText(getApplicationContext(),s,Toast.LENGTH_LONG).show();
}

@Override
protected String doInBackground(Void... params) {

HashMap<String, String> data = new HashMap<String,String>();
data.put(Configs.KEY_TYPE,claimType);
data.put(Configs.KEY_AMOUNT,Amount);
data.put(Configs.KEY_IMAGEDESCRIPTION,Description);
String uploadImage=getStringImage(photo);
data.put(Configs.KEY_IMAGE,uploadImage);
data.put(Configs.KEY_TSID,IDFromInfo);
RequestHandler rh=new RequestHandler();
String result = rh.sendPostRequest(Configs.ADD_WORKFORCE,data);
return result;
}
}

AddImage ru = new AddImage();
ru.execute(claimType, Amount, Description, photo); // error
}

错误

Error:(185, 11) error: method execute in class AsyncTask<Params,Progress,Result> cannot be applied to given types;
required: Void[]
found: String,String,String,Bitmap
reason: varargs mismatch; String cannot be converted to Void
where Params,Progress,Result are type-variables:
Params extends Object declared in class AsyncTask
Progress extends Object declared in class AsyncTask
Result extends Object declared in class AsyncTask

最佳答案

试试这个方法,

        public void Add(final String claimType, final String Amount, final String Description,  final Bitmap photo)
{
new AddImage().execute();
}

class AddImage extends AsyncTask<Void, Void, String> {
ProgressDialog loading;

@Override
protected void onPreExecute() {
super.onPreExecute();
loading = ProgressDialog.show(getApplicationContext(), "Please Wait",null, true, true);
}

@Override
protected void onPostExecute(String s) {
super.onPostExecute(s);
loading.dismiss();
Toast.makeText(getApplicationContext(),s,Toast.LENGTH_LONG).show();
}

@Override
protected String doInBackground(Void... params) {

HashMap<String, String> data = new HashMap<String,String>();
data.put(Configs.KEY_TYPE,claimType);
data.put(Configs.KEY_AMOUNT,Amount);
data.put(Configs.KEY_IMAGEDESCRIPTION,Description);
String uploadImage=getStringImage(photo);
data.put(Configs.KEY_IMAGE,uploadImage);
data.put(Configs.KEY_TSID,IDFromInfo);
RequestHandler rh=new RequestHandler();
String result = rh.sendPostRequest(Configs.ADD_WORKFORCE,data);
return result;
}
}

关于android - 错误 : method execute in class AsyncTask<Params, Progress,Result> 无法应用于给定类型,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/34651009/

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