error: method execute in class AsyncTask<Params,Progress,Result> cannot be applied to given types
error: method execute in class AsyncTask<Params,Progress,Result> cannot be applied to given types
我想通过 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
您的 doInBackground 希望您不传递任何参数(Void... params),而您传递了 4 个参数(claimType、Amount、Description、photo)
像这样使用 AsyncTask
:
class AddImage extends AsyncTask<String, Void, String>
并在 doInBackground(String... params) 中获取字符串为:
@Override
protected String doInBackground(String... params) {
HashMap<String, String> data = new HashMap<String,String>();
data.put(Configs.KEY_TYPE,params[1]);
data.put(Configs.KEY_AMOUNT,params[2]);
data.put(Configs.KEY_IMAGEDESCRIPTION,params[3]);
}
试试这个方法,
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;
}
}
我想通过 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
您的 doInBackground 希望您不传递任何参数(Void... params),而您传递了 4 个参数(claimType、Amount、Description、photo)
像这样使用 AsyncTask
:
class AddImage extends AsyncTask<String, Void, String>
并在 doInBackground(String... params) 中获取字符串为:
@Override
protected String doInBackground(String... params) {
HashMap<String, String> data = new HashMap<String,String>();
data.put(Configs.KEY_TYPE,params[1]);
data.put(Configs.KEY_AMOUNT,params[2]);
data.put(Configs.KEY_IMAGEDESCRIPTION,params[3]);
}
试试这个方法,
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;
}
}