bMon
bMon

Reputation: 962

AsyncTask not working - cannot instantiate the type error

I have a public class FriendMaps extends MapActivity that gets called from a menu item when selected, and at the end of that I have private abstract class DownloadFilesTask extends AsyncTask<Void, Void, Void> in there I do some server calls and put data into local arrays etc.

But in my public void onCreate(Bundle savedInstanceState) of the FriendMaps activity I call new DownloadFilesTask().execute(); and get the following error:

Error: Cannot instantiate the type FriendMaps.DownloadFilesTask

From the documentation:

AsyncTask must be subclassed to be used.

That would be accomplished DownloadFilesTask extends AsyncTask there.

The task instance must be created on the UI thread

Maybe this is where I am confused? To my understanding the UI thread is the current activity being displayed - if so then the onCreate of the FriendMaps activity is the correct place to execute();

If full code spinets are required for further help, please comment and I'll add where needed.

Upvotes: 0

Views: 1587

Answers (2)

Nanne
Nanne

Reputation: 64399

You might want to make your declaration like this

private class DownloadFilesTask extends AsyncTask<Void, Void, Void>

You probably didn't mean it to be an abstract class, and as @maid450 said, you can't instantiate an abstract class.

Upvotes: 0

maid450
maid450

Reputation: 7486

You can't instantiate it because you declared DownloadFilesTask as an abstract class, that, by definition, cannot be instantiated

Upvotes: 5

Related Questions