erythraios
erythraios

Reputation: 339

AsyncTask missing return statement

Android Studio is insisting that I am missing a return value in doInBackground, even though it seems to be declared as Void. Am I overlooking something?

AsyncTask<Boolean, Void, Void> initiateConnection = new AsyncTask<WebSocketClient, Void, Void>() {
        @Override
        protected Void doInBackground(WebSocketClient ... clients) {
            clients[0].connect();
        }

        @Override
        protected void onPostExecute(Void result) {
            Log.i(st, "Socket connected.");
        }
    };
    initiateConnection.execute();
}

Upvotes: 1

Views: 1886

Answers (2)

Green goblin
Green goblin

Reputation: 9996

You need to return null

protected Void doInBackground(WebSocketClient ... clients) {
    clients[0].connect();

    return null;
}

Upvotes: 2

CommonsWare
CommonsWare

Reputation: 1006809

Void (uppercase V) is not void (lowercase v). With void, you can just "fall off the bottom of the method". With Void, you need to explicitly return something, typically null.

Upvotes: 9

Related Questions