Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
2.1k views
in Technique[技术] by (71.8m points)

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

'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?

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)

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)


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...