如何修复 android studio 3 中的“找不到符号类 Nullable"错误
我正在使用 android studio 3.2,并且想在我的空白类中使用 SQLiteOpenHelper.当我运行项目 java 编译器返回错误:找不到符号类 Nullable
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);
}}
我也用过这个实现
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
提前致谢
使用:
implementation 'androidx.annotation:annotation:1.1.0'
如果你实现了com.android.support:support-annotations
,那么你需要使用android.support.annoation.Nullable
.
If you implement com.android.support:support-annotations
, then you need to use android.support.annoation.Nullable
.
如果您不完全限定名称,而只需使用 @Nullable
代替,这会容易得多.然后,Android Studio 将为您提供可用的导入.
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.
如果您实际上是针对 API 24,就像您列出的实现所说的那样,您根本无法使用 AndroidX.AndroidX 要求 targetSdkVersion
为 28 或更高.
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.