问题
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