I want to use annotations for NonNull, Nullable and UnsopportedAppUsage in my Handler-file, but the 2nd, 3rd and 4th line gives me an error. How do I fix this?
package android.os;
import android.support.annotation.NonNull;
import android.support.annotation.Nullable;
import android.annotation.UnsupportedAppUsage;
import android.util.Log;
import android.util.Printer;
The answer is two-fold. For @NonNull and @Nullable do the following:
If you use androidx you need to add
implementation 'androidx.annotation:annotation:1.0.2'
or if you use the legacy support library (your imports are for this version)
implementation 'com.android.support:support-annotations:28.0.0'
to your dependencies in the build.gradle file.
The version numbers might be different for you.
Note that there is also the
android.annotation.Nullableclass, but it's internal API of Android-OS (causing build errors if used).
For @UnsupportedAppUsage:
This annotation denotes that something that is internal to the Android SDK and shouldn't be used is actually in use. Using this annotation in your code doesn't make a whole lot of sense. Additionally the annotation is hidden in the SDK and cannot be used by you.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With