Reputation: 11
My Asynctask is throwing this error
"Caused by java.lang.ClassCastException: java.lang.Object[] cannot be cast to java.lang.Void[]"
code:
protected Object doInBackground(Void... params)
on above method for only specific user not for all users.Can any one tell does passing void like "AsyncTask Void,Void,Object" is cause for my problem? below i attach my code
private class RegisterTask extends
AsyncTask<Void, Void, Object>
{
protected void onPreExecute() {
super.onPreExecute();
}
}
protected Object doInBackground(Void... params) {
return null;
}
protected void onPostExecute(Object result) {
super.onPostExecute(result);
}
}`
Upvotes: 1
Views: 708
Reputation: 2437
You can create the AsyncTask with an Object as a parameter even if you not used it would not harm
private class RegisterTask extends AsyncTask<Object, Void, Object>
{
protected void onPreExecute() {
super.onPreExecute();
}
}
protected Object doInBackground(Object... params) {
return null;
}
protected void onPostExecute(Object result) {
super.onPostExecute(result);
}
}
Alternate is the way you have been initializing your AsyncTask is it a generic way like ?
//Change
AsyncTask asyncTask = new RegisterTask (...);
Then please remove above and create your AsyncTask with the correct parameter declaration side.
AsyncTask<Void, Void, Object> asyncTask = new RegisterTask (...);
Upvotes: 1
Reputation: 1506
Check the parameter passed to new RegisterTask().execute()
method. Perhaps you used Object
type rather than Void
.
Change your RegisterTask
class to extend AsyncTask <Object, Void, Object>
. Learn more about AsyncTask
here.
Upvotes: 3