0

So, I'm trying to run the simplest AsyncTask possible: it doesn't accept parameters, it just runs a function, gets the result string and displays is. And no matter what I try, I get this error:

java.lang.ClassCastException: java.lang.Object[] cannot be cast to java.lang.Void[] at (...)$AsyncTaskRunner.doInBackground

The AsyncTask:

    private class AsyncTaskRunner extends AsyncTask<Void, Void, String> {

        @Override
        protected void onPreExecute() {
            resultText.setText("");
            progressBar.setVisibility(View.VISIBLE);
        }

        @Override
        protected String doInBackground(Void... params) {
            return "test";
        }

        @Override
        protected void onPostExecute(String result) {
            progressBar.setVisibility(View.GONE);
            resultText.setText(result);
        }
    }

And this is how I call it:

        buttonCalculate.setOnClickListener(new View.OnClickListener() {
            public void onClick(View v) {
                if (AsyncTaskRunner != null) {
                    AsyncTaskRunner.cancel(true);
                }

                AsyncTaskRunner = new AsyncTaskRunner();
                AsyncTaskRunner.execute();
            }
        });

What am I doing wrong here?

a_local_nobody
  • 7,947
  • 5
  • 29
  • 51
PaulJK
  • 189
  • 11

1 Answers1

0

OK, so curiously it works if I call it like this:

AsyncTask<Void, Void, String> asyncTaskRunner = new AsyncTaskRunner();
asyncTaskRunner.execute();
PaulJK
  • 189
  • 11