Android: cannot specify list for asynctask. Return type: doinbackground

I have the following asynctask based code block. I try to return a list variable by returning loadfeed(), and the return type of doinbackground is string. If I change the return type of doinbackground from string to list, then I receive an error

"The return type is incompatible with AsyncTask<String,Void,String>.doInBackground(String[])"

How can I solve this error? Please help

thank you,

  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);

   }
}

resolvent:

Change your class definition to:

class DispData extends AsyncTask<String, Object, List<String>>

This forces the doinbackground declaration to be:

protected List<String> doInBackground(String... arg);

The content of this article comes from the network collection of netizens. It is used as a learning reference. The copyright belongs to the original author.
THE END
分享
二维码
< <上一篇
下一篇>>