-1

i created an AsyncTask as shown below in the code so that the value to be published through onPublishProgress is of type double, but at run time i receive the below posted logCat errors

please help me to find the reason why i am getting this error

Code:

this.mbtnShowComp.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View v) {
           mATComputations = new mATComputations();
            mATComputations.execute();
        }
    });

private class mATComputations extends AsyncTask <Void, Double, Void> {

    private int mI = 0;
    private double mResult;


    @Override
    protected Void doInBackground(Void... params) {
        Log.w(TAG, CSubTag.msg("mATComputations.doInBackground"));

        while (!isCancelled()) {
            this.mResult += (((++this.mI)/10) * (50));
            publishProgress(this.mResult);
        }
        return null;
    }

    @Override
    protected void onProgressUpdate(Double... values) {
        super.onProgressUpdate(values);
        Log.w(TAG, CSubTag.msg("mATComputations.onProgressUpdate"));

        mtvComputations.setText(""+(values[0]));
    }

    @Override
    protected void onPostExecute(Void aVoid) {
        super.onPostExecute(aVoid);
        Log.w(TAG, CSubTag.msg("mATComputations.onPostExecute"));
    }

    @Override
    protected void onCancelled() {
        super.onCancelled();
        Log.w(TAG, CSubTag.msg("mATComputations.onCancelled"));
    }
}

logcat

FATAL EXCEPTION: AsyncTask #2
    01-14 10:59:47.220 953-1958/com.example.com.bt_11 E/AndroidRuntime: Process: com.example.com.bt_11, PID: 953
    01-14 10:59:47.220 953-1958/com.example.com.bt_11 E/AndroidRuntime: java.lang.RuntimeException: An error occured while executing doInBackground()
    01-14 10:59:47.220 953-1958/com.example.com.bt_11 E/AndroidRuntime:     at android.os.AsyncTask$3.done(AsyncTask.java:300)
    01-14 10:59:47.220 953-1958/com.example.com.bt_11 E/AndroidRuntime:     at java.util.concurrent.FutureTask.finishCompletion(FutureTask.java:355)
    01-14 10:59:47.220 953-1958/com.example.com.bt_11 E/AndroidRuntime:     at java.util.concurrent.FutureTask.setException(FutureTask.java:222)
    01-14 10:59:47.220 953-1958/com.example.com.bt_11 E/AndroidRuntime:     at java.util.concurrent.FutureTask.run(FutureTask.java:242)
    01-14 10:59:47.220 953-1958/com.example.com.bt_11 E/AndroidRuntime:     at android.os.AsyncTask$SerialExecutor$1.run(AsyncTask.java:231)
    01-14 10:59:47.220 953-1958/com.example.com.bt_11 E/AndroidRuntime:     at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1112)
    01-14 10:59:47.220 953-1958/com.example.com.bt_11 E/AndroidRuntime:     at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:587)
    01-14 10:59:47.220 953-1958/com.example.com.bt_11 E/AndroidRuntime:     at java.lang.Thread.run(Thread.java:818)
    01-14 10:59:47.220 953-1958/com.example.com.bt_11 E/AndroidRuntime:  Caused by: java.lang.ClassCastException: java.lang.Object[] cannot be cast to java.lang.Void[]
    01-14 10:59:47.220 953-1958/com.example.com.bt_11 E/AndroidRuntime:     at com.example.com.bt_11.ActConnect2$mATComputations.doInBackground(ActConnect2.java:1902)
    01-14 10:59:47.220 953-1958/com.example.com.bt_11 E/AndroidRuntime:     at android.os.AsyncTask$2.call(AsyncTask.java:288)
    01-14 10:59:47.220 953-1958/com.example.com.bt_11 E/AndroidRuntime:     at java.util.concurrent.FutureTask.run(FutureTask.java:237)
    01-14 10:59:47.220 953-1958/com.example.com.bt_11 E/AndroidRuntime:     at android.os.AsyncTask$SerialExecutor$1.run(AsyncTask.java:231) 
    01-14 10:59:47.220 953-1958/com.example.com.bt_11 E/AndroidRuntime:     at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1112) 
    01-14 10:59:47.220 953-1958/com.example.com.bt_11 E/AndroidRuntime:     at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:587) 
    01-14 10:59:47.220 953-1958/com.example.com.bt_11 E/AndroidRuntime:     at java.lang.Thread.run(Thread.java:818) 
Eric B.
  • 4,622
  • 2
  • 18
  • 33
Amrmsmb
  • 1
  • 27
  • 104
  • 226

1 Answers1

1

This will help you: Object[] cannot be cast to Void[] in AsyncTask.

Basically, you probably have error in your mATComputations class and reference names (are they the same?) or you declared mATComputations variable as AsyncTask instead of your own class.

Please rename your mATComputations class to have proper Capital Name (eg. ATComputations).

Instantiating and executing the task should look like this:

ATComputations mATComputations = new ATComputations();
mATComputations.execute();
Community
  • 1
  • 1
Rafal Zawadzki
  • 963
  • 6
  • 15