0

编译器错误是“ The method execute(ArrayList<String>...) in the type AsyncTask<ArrayList<String>,Void,ArrayList<String>> is not applicable for the arguments (String)

为什么它不接受新参数?谁能看到我做错了什么?

   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;

        }
4

4 回答 4

2

您有new myTask().execute(logicalUrl)logicalUrl is String,但您在通用中指定了应该是ArrayList<String>

所以改成

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

或添加为ArrayList您创建的类的参数。

new myTask().execute(passing);

现在它应该可以工作了。看来你只是忽略了它:]

于 2012-06-09T15:19:17.410 回答
2

改变:

new myTask().execute(logicalUrl);

到:

new myTask().execute(passing);
于 2012-06-09T15:20:20.160 回答
1

new myTask().execute(passing);代替new myTask().execute(logicalUrl);

于 2012-06-09T15:20:14.640 回答
1

你的方法应该是这样的

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

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

        return true;

并检查此链接。,。它类似于你的问题

将参数传递给 AsyncTask,并返回结果

于 2012-06-09T15:29:22.610 回答