Object[] Cannot Be Cast To Void[] In Asynctask
Solution 1:
Solution found:
the problem was this:
AsyncTaskmAsyncTask=newListPalinasAsynkTask(callback);
....
mAsyncTask.execute();
I'm using generic AsyncTask to call execute, that class would pass Void as a parameter and will never call .execute() on ListPalinasAsynkTask, instead it will call ListPalinasAsynkTask.execute(Void). That gives the error.
Solutions:
- Use ListPalinasAsynkTask instead of generic AsyncTask
- Better one: Create a new class VoidRepeatableAsyncTask and make other Void AsyncTasks extend that one.
Like this:
publicabstractclassVoidRepeatableAsyncTask<T> extendsRepeatableAsyncTask<Void, Void, T> {
publicvoidexecute() {
super.execute();
}
}
Then you can easily use something like this to call execute:
VoidRepeatableAsyncTaskmAsyncTask=newListPalinasAsynkTask(callback);
....
mAsyncTask.execute();
This will call the no-parameters execute method of AsyncTask.
Solution 2:
An alternative way with which I solved it is to pass Object
in parameters, even if you don't use the parameters.
new AsyncTask<Object, Void, MergeAdapter>()
and the override:
@OverrideprotectedReturnClassdoInBackground(Object... params) {
//...
}
The above applies (in my case) if you want to pass different types of AsyncTasks to a method and of course you do not care about the parameters.
Solution 3:
The solution is much simpler as I see it. Just create the subclass object in this way:
AsyncTask<Void, Void, List<Palina> mAsyncTask = new ListPalinasAsynkTask(callback);
....
mAsyncTask.execute();
Solution 4:
Try using:
result = repeatInBackground((Void) inputs);
instead of
result = repeatInBackground(inputs);
Solution 5:
If this problem is occurring then you might have created a Derived class object and added its the base class variable (AsyncTask). So this error is occurring. AsyncTask mAsyncTask = new ListPalinasAsynkTask(callback);
Lint also gives a warning when you do like this "Unchecked call to execute. Params ...."
The solution is ListPalinasAsynkTask mAsyncTask = new ListPalinasAsynkTask(callback); Then call execute on it. It will work fine
Post a Comment for "Object[] Cannot Be Cast To Void[] In Asynctask"