How to remove warnings of nullable in Android?

Viewed 1008

I'm using annotations library supported by Android. It is useful for checking NullpointerExceptions. But, it also annoying if I checked the variable if it is null.

In this case:

@Nullable
String value;

boolean isValid(String target) {
    return (target != null && target.length() > 0);
}

void test() {
    if (isValid(value)) {
        Log.d("TEST", value);
        // Do something.
    }
}

In above code, I already checked if 'value' is null, but still got the warning of "It maybe produce NullPointerException".

Is there some annotations that I checked null-type in this function?

2 Answers

You can use the annotation:

@SuppressWarnings("ConstantConditions")

In android studio Go to

file-->other settings---> default settings (defaultpreference)--->inspections--->java---> @notnull and nullable Probelms

uncheck it and click ok.

Related