简体   繁体   中英

AsyncTask throwing Error “Caused by java.lang.ClassCastException: java.lang.Object[] cannot be cast to java.lang.Void[]” on doinbackground()

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

}`

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 .

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 (...);

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM