'android.annotation.NonNull' is not public in 'android.annotation'. Cannot be accessed from outside package
Asked Answered
P

2

7

'android.annotation.NonNull' is not public in 'android.annotation'. Cannot be accessed from outside package

I get this warning when I try to list data. Does anyone know why?

Pentavalent answered 23/4, 2020 at 12:37 Comment(0)
S
12

You're referring to the Android platform's internal annotations, which aren't the ones you want to use for your own code. For your code, you should import the AndroidX versions of those annotations:

androidx.annotation.NonNull

androidx.annotation.Nullable

etc. (note the extra x in androidx vs android)

You'll also want to make sure you have declared a dependency on androidx.annotation:annotation in your build.gradle (see here for the latest version information)

Santosantonica answered 24/4, 2020 at 5:34 Comment(0)
P
0

Add the dependencies for the artifacts you need in the build.gradle file for your app or module:

dependencies {
    implementation "androidx.annotation:annotation:1.8.0"
    // To use the Java-compatible @androidx.annotation.OptIn API annotation
    implementation "androidx.annotation:annotation-experimental:1.4.1"
}

Final click Sync Now

Poster answered 12/6 at 13:9 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.