Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/dart/3.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Android 我能';t将字符串数组传递给我的异步任务_Android - Fatal编程技术网

Android 我能';t将字符串数组传递给我的异步任务

Android 我能';t将字符串数组传递给我的异步任务,android,Android,编译器错误为“类型AsyncTask中的方法execute(ArrayList…)不适用于参数(字符串)” 为什么它不接受新参数?有人能看出我做错了什么吗 ArrayList<String> passing = new ArrayList<String>(); passing.add(logicalUrl); passing.add("filename.pdf"); new myTask().e

编译器错误为“
类型AsyncTask中的方法execute(ArrayList…)不适用于参数(字符串)

为什么它不接受新参数?有人能看出我做错了什么吗

   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;

        }
ArrayList passing=new ArrayList();
通过。添加(logicalUrl);
passing.add(“filename.pdf”);
新建myTask().execute(logicalUrl);
返回true;
}
公共类myTask扩展了AsyncTask{
进程对话;
@凌驾
受保护的void onPreExecute(){
dialog=新建进度对话框(ModuleContents.this);
setTitle(“下载…”);
setMessage(“请稍候…”);
对话框。setUndeterminate(true);
dialog.show();
}
受保护的ArrayList doInBackground(ArrayList…通过){
ArrayList passed=正在传递[0];
字符串physicalUrl=parsePhysicalUrl(passed.get(0));
字符串文件名=passed.get(1);
试一试{
保存文件(物理URL,文件名);
}捕获(客户端协议例外e){
e、 printStackTrace();
}捕获(IOE异常){
e、 printStackTrace();
}
返回通过;
}
您有了
新的myTask().execute(logicalUrl)
logicalUrl是
字符串
,但您在泛型中指定了应为
ArrayList

所以把它改成

 public class myTask extends AsyncTask<String, Void, ArrayList<String>> {}
现在它应该可以工作了。你似乎只是忽略了它:

你有了
新的myTask().execute(logicalUrl)
logicalUrl是
String
,但是你在泛型中指定了
ArrayList

所以把它改成

 public class myTask extends AsyncTask<String, Void, ArrayList<String>> {}
现在它应该可以工作了。你似乎只是忽略了它:

new myTask().execute(passing);
而不是
new myTask().execute(logicalUrl);
new myTask().execute(passing);
而不是
new myTask().execute(logicalUrl);
更改:

new myTask().execute(logicalUrl);
致:

更改:

new myTask().execute(logicalUrl);
致:


你的方法应该是这样的

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

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

        return true;
ArrayList passing=new ArrayList();
通过。添加(logicalUrl);
passing.add(“filename.pdf”);
**新建myTask()。执行(传递)**
返回true;
并检查此链接。它与您的问题类似


您的方法应该是这样的

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

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

        return true;
ArrayList passing=new ArrayList();
通过。添加(logicalUrl);
passing.add(“filename.pdf”);
**新建myTask()。执行(传递)**
返回true;
并检查此链接。它与您的问题类似