2012-06-09 21 views
0

編譯器錯誤是「The method execute(ArrayList<String>...) in the type AsyncTask<ArrayList<String>,Void,ArrayList<String>> is not applicable for the arguments (String)我無法通過一個字符串數組來我的AsyncTask

爲什麼不是接受新的參數?任何人都可以看到我做錯了什麼?

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; 

     } 

回答

2

new myTask().execute(logicalUrl) logicalUrl是String,但你在一般的規定,應該是ArrayList<String>

所以將其更改爲

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

或者添加爲ArrayList類所創建的參數。

new myTask().execute(passing); 

現在它應該工作。看來你只能忽略它:]

1

new myTask().execute(passing);,而不是new myTask().execute(logicalUrl);

2

變化:

new myTask().execute(logicalUrl); 

要:

new myTask().execute(passing); 
1

你的方法應該喜歡這個

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

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

     return true; 

並檢查此鏈接。,。其類似於你的問題

Passing arguments to AsyncTask, and returning results

相關問題