2

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

Majid Tabibpour
  • 458
  • 3
  • 5
  • 16

2 Answers2

8

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.

Martin Zeitler
  • 1
  • 19
  • 155
  • 216
TheWanderer
  • 16,775
  • 6
  • 49
  • 63
  • Caution: It may cause build error going ahead. Read [this](https://stackoverflow.com/a/61642114/1911652) – Atul May 06 '20 at 18:05
0

I solve my problem adding

android.useAndroidX=true
android.enableJetifier=true

in my gradle.properties file

Dey
  • 842
  • 9
  • 21
  • 1
    Caution: It may cause build error going ahead. Read [this](https://stackoverflow.com/a/61642114/1911652) – Atul May 06 '20 at 18:05