How to fix 'cannot find symbol class Nullable' error in android studio 3

你。 提交于 2020-05-14 12:09:05

问题


i'm using android studio 3.2 , and want to use SQLiteOpenHelper in my blank class . when i have run project java compiler return error : cannot find symbol class Nullable

public class Db extends SQLiteOpenHelper {
public Db(@androidx.annotation.Nullable Context context, @androidx.annotation.Nullable String name, @androidx.annotation.Nullable SQLiteDatabase.CursorFactory factory, int version) {
    super(context, name, factory, version);
}}

I also used this implementation

implementation 'com.android.support:support-annotations:24.2.0'

I clicked Invalidate caches and restart on file menu and rebuild project but error still occurs

Thank you in advance


回答1:


Use:

implementation 'androidx.annotation:annotation:1.1.0'

If you implement com.android.support:support-annotations, then you need to use android.support.annoation.Nullable.

It's a lot easier if you don't fully qualify the names, and just use @Nullable instead. Android Studio will then give you available imports.

If you are actually targeting API 24, like the implementation you list says you are, you simply can't use AndroidX. AndroidX requires a targetSdkVersion of 28 or higher.




回答2:


I solve my problem adding

android.useAndroidX=true
android.enableJetifier=true

in my gradle.properties file



来源:https://stackoverflow.com/questions/54043256/how-to-fix-cannot-find-symbol-class-nullable-error-in-android-studio-3

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!