Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Android Lint warning: "Redundant array creation for calling varargs method"

I am getting the above Lint warning in my Android project for the new Void[] {} part of the following code:

new AsyncTask<Void, Void, Exception>() {

    @Override
    protected void onPreExecute() {
        showToast("Restarting NFC...");
    }

    @Override
    protected Exception doInBackground(Void... params) {
        try {
            disableNfcForegroundDispatch();
            Thread.sleep(1000L);
            enableNfcForegroundDispatch();
            return null;
        }
        catch (Exception e) {
            return e;
        }
    }

    @Override
    protected void onPostExecute(Exception e) {
        if (e == null) {
            showToast("...NFC restarted.");
        }
        else {
            Log.e(LOG_TAG, "Could not restart NFC!", e);
            showToast("Could not restart NFC: " + e);
        }
    }

}.execute(new Void[] {});

I am unable to replace the problematic new Void[] {} with null, so what is the correct solution?

like image 472
ban-geoengineering Avatar asked Dec 06 '25 07:12

ban-geoengineering


1 Answers

Leave the argument list empty:

.execute();
like image 124
laalto Avatar answered Dec 07 '25 20:12

laalto



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!