1

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);
    }

}`
Phantômaxx
  • 37,901
  • 21
  • 84
  • 115

2 Answers2

3

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.

Muhammadjon
  • 1,476
  • 2
  • 14
  • 35
  • This issue for only specific user only im not able to replicate this issue.im not sure that changing " Void to Object" fix my issue.Any way thanks for support.code running successfully. – lakshmi narayanan Jun 22 '18 at 07:36
1

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 (...);
Rizwan
  • 2,369
  • 22
  • 27