I have the following block of code based on an asynctask. I'm trying to return a List variable via return LoadFeed() and the return type of doInBackground is String. If I change the return type of doInBackground from String to List then I get an error
"The return type is incompatible with AsyncTask<String,Void,String>.doInBackground(String[])"
How do I fix this error? Please help
Thanks,
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);
}
}
Change your class definition to:
class DispData extends AsyncTask<String, Object, List<String>>
This will force the doInBackground declaration to become:
protected List<String> doInBackground(String... arg);
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With