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?