Android:无法为AsyncTask指定List <String>返回类型:doInBackground

sam*_*ude 3 android list android-asynctask

我有以下基于asynctask的代码块.我试图通过返回LoadFeed()返回List变量,并且doInBackground的返回类型是String.如果我将doInBackground的返回类型从String更改为List,那么我会收到错误

"The return type is incompatible with AsyncTask<String,Void,String>.doInBackground(String[])"
Run Code Online (Sandbox Code Playgroud)

我该如何解决这个错误?请帮忙

谢谢,

  private class DispData extends AsyncTask<String, Void, String> {
   private final ProgressDialog dialog = new ProgressDialog(MessageList.this);
   // can use UI thread here
   protected void onPreExecute() {
      dialog.setMessage("Fetching scores...");
      dialog.show();
   }


   // automatically done on worker thread (separate from UI thread)
   protected String doInBackground(final String... args) {
      return loadFeed();

   }


  // can use UI thread here
   protected void onPostExecute(final List<String> result) {
      if (dialog.isShowing()) {
         dialog.dismiss();
      }
     adapter = 
            new ArrayAdapter<String>(MessageList.this,R.layout.row,result);
     MessageList.this.setListAdapter(adapter);

   }
}
Run Code Online (Sandbox Code Playgroud)

Bre*_*den 16

将您的班级定义更改为:

class DispData extends AsyncTask<String, Object, List<String>>
Run Code Online (Sandbox Code Playgroud)

这将强制doInBackground声明成为:

protected List<String> doInBackground(String... arg);
Run Code Online (Sandbox Code Playgroud)