Issue
I have to load XML data in my app, I'm doing that in a subclass of my activity class extending AsyncTask like this :
public class MyActivity extends Activity {
ArrayList<Offre> listOffres;
private class DownloadXML extends AsyncTask<Void, Void,Void>
{
protected Void doInBackground(Void... params)
{
listOffres = ContainerData.getFeeds();
return null;
}
}
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
requestWindowFeature(Window.FEATURE_NO_TITLE);
setContentView(R.layout.activity_liste_offres);
DownloadXML.execute(); // Problem here !
for(Offre offre : listOffres) { // etc }
}
}
I don't know how to use execute() here, I have the following error :
Cannot make a static reference to the non-static method execute(Integer...) from the type AsyncTask
I guess some parameters but what ?
Thank you.
Solution
You need to create an instance of your DonwloadXML
file and call execute()
on that method:
DownloadXML task=new DownloadXML();
task.execute();
EDIT: you should probably also return the listOffers
from your doInBackground()
and process the array in the onPostExecute()
method of your AsynTask
. You can have a look at this simple AsyncTask tutorial.
Answered By - Ovidiu Latcu
0 comments:
Post a Comment
Note: Only a member of this blog may post a comment.