user5256621
user5256621

Reputation:

error: method execute in class AsyncTask<Params,Progress,Result> cannot be applied to given types

I'm wanted to send text and image from android to MySQL through php. However, I get error and not able to solve. Can someone help me to figure it out the problem? Thanks a lot

Add Function

 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

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

Upvotes: 3

Views: 2449

Answers (3)

Sazzad Hissain Khan
Sazzad Hissain Khan

Reputation: 40226

Try this way,

        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;
            }
        }

Upvotes: 1

Kapil Rajput
Kapil Rajput

Reputation: 11555

Use AsyncTask like this :

class AddImage extends AsyncTask<String, Void, String>

and in doInBackground(String... params) get string's as :

        @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]);

}

Upvotes: 0

Hemix
Hemix

Reputation: 313

Your doInBackground expects you to pass no param (Void... params) and you pass 4 params (claimType, Amount, Description, photo)

Upvotes: 1

Related Questions