Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Java: Illegal type 'void' in ASyncTask

Hopefully you can shine some light on this for me.

I'm trying to create the following AsyncTask in Java for an Android app. When I enter the below code, Android Studio highlights both the 'void' params with the error:

"Illegal Type: Void".

After a number of google searches I still can't understand what the problem is here (and in honesty, I'm quite confused about the whole thing!).

private class BackgroundTask extends AsyncTask<URL, void, void> {

    protected void doInBackground(URL... inputURL) {

        URL searchURL = inputURL[0];

        //Step 2: Get Data
        String JSONdata = getJSONdata(searchURL);

        //Step 3: Parse JSON
        ArrayList books = parseJSON(JSONdata);

        updateUI(books);

    }
}

Appreciate any info you can send my way!

like image 812
Caphson Avatar asked Jul 31 '16 19:07

Caphson


2 Answers

use the class instead, capital V

private class BackgroundTask extends AsyncTask<URL, Void, Void> {
like image 187
ΦXocę 웃 Пepeúpa ツ Avatar answered Sep 23 '22 14:09

ΦXocę 웃 Пepeúpa ツ


AsyncTask uses generics. So use Void instead of void. Similarly, if you want to use integer use Integer and not int.

like image 28
Embydextrous Avatar answered Sep 26 '22 14:09

Embydextrous