124697
124697

Reputation: 21893

I can't pass a String array to my AsyncTask

The compiler error is "The method execute(ArrayList<String>...) in the type AsyncTask<ArrayList<String>,Void,ArrayList<String>> is not applicable for the arguments (String)"

Why wouldn't it accept the new parameter? can anyone see what i am doing wrong?

   ArrayList<String> passing = new ArrayList<String>();
            passing.add(logicalUrl);
            passing.add("filename.pdf");
            new myTask().execute(logicalUrl);
            return true;
        }

    public class myTask extends AsyncTask<ArrayList<String>, Void, ArrayList<String>> {
        ProgressDialog dialog;

        @Override
        protected void onPreExecute() {
            dialog = new ProgressDialog(ModuleContents.this);
            dialog.setTitle("Downloading...");
            dialog.setMessage("Please wait...");
            dialog.setIndeterminate(true);
            dialog.show();
        }

        protected ArrayList<String> doInBackground(ArrayList<String>... passing) {
            ArrayList<String> passed = passing[0];
            String physicalUrl = parsePhysicalUrl(passed.get(0));
            String filename = passed.get(1);
            try {
                globals.saveFile(physicalUrl, filename);
            } catch (ClientProtocolException e) {
                e.printStackTrace();
            } catch (IOException e) {
                e.printStackTrace();
            }
            return passed;

        }

Upvotes: 0

Views: 5565

Answers (4)

stay_hungry
stay_hungry

Reputation: 1448

Your method should like this

 ArrayList<String> passing = new ArrayList<String>();
        passing.add(logicalUrl);
        passing.add("filename.pdf");

        **new myTask().execute(passing);**

        return true;

And Check this link.,. its similara to your question

Passing arguments to AsyncTask, and returning results

Upvotes: 1

Simon Dorociak
Simon Dorociak

Reputation: 33505

You have new myTask().execute(logicalUrl) logicalUrl is String but you specified in generic that should be ArrayList<String>

So change it to

 public class myTask extends AsyncTask<String, Void, ArrayList<String>> {}

or add as argument of your class ArrayList that you created.

new myTask().execute(passing);

and now it should work. It seems you only overlooked it :]

Upvotes: 2

waqaslam
waqaslam

Reputation: 68177

Change:

new myTask().execute(logicalUrl);

To:

new myTask().execute(passing);

Upvotes: 2

abbas.aniefa
abbas.aniefa

Reputation: 2905

new myTask().execute(passing); instead of new myTask().execute(logicalUrl);

Upvotes: 1

Related Questions