我的app数据库类

@Database(entities = {Detail.class}, version = Constant.DATABASE_VERSION)
public abstract class AppDatabase extends RoomDatabase {

    private static AppDatabase INSTANCE;

    public abstract FavoritesDao favoritesDao();

    public static AppDatabase getAppDatabase(Context context) {
        if (INSTANCE == null) {
            INSTANCE =
                    Room.databaseBuilder(context.getApplicationContext(), AppDatabase.class, Constant.DATABASE).allowMainThreadQueries().build();

                    //Room.inMemoryDatabaseBuilder(context.getApplicationContext(),AppDatabase.class).allowMainThreadQueries().build();
        }
        return INSTANCE;
    }

    public static void destroyInstance() {
        INSTANCE = null;
    }
}

Gradle自由:

 compile "android.arch.persistence.room:runtime:+"   
 annotationProcessor "android.arch.persistence.room:compiler:+"

当我请求实例时,它会给出这个错误,AppDatabase_Impl不存在 在我的应用课上

public class APp extends Application {

    private boolean appRunning = false;

    @Override
    public void onCreate() {
        super.onCreate();
        AppDatabase.getAppDatabase(this); //--AppDatabase_Impl does not exist

    }   

}

当前回答

我错过的时候出现了这个错误

@Database(entity="{<model.class>})

确保上面注释中指定的实体模型引用特定的模型类,并确保必要的注释:

@Entity(tableName = "<table_name>" ...)

是正确定义的,你会很好吗

其他回答

确保在build.gradle中为room添加正确的依赖项

ext {
   roomVersion = '2.1.0-alpha06'
}

// Room components
implementation "androidx.room:room-runtime:$rootProject.roomVersion"
implementation "androidx.room:room-ktx:$rootProject.roomVersion"
kapt "androidx.room:room-compiler:$rootProject.roomVersion"
androidTestImplementation "androidx.room:room-testing:$rootProject.roomVersion"

在上面这条线下面

apply plugin: 'kotlin-kapt'

同意以上回答

解决方法如下。如下所示,将annotationProcessor更改为kapt

// annotationProcessor "androidx.room:room-compiler:$room_version"
implementation "androidx.room:room-runtime:$room_version"
kapt "androidx.room:room-compiler:$room_version"

我错过的时候出现了这个错误

@Database(entity="{<model.class>})

确保上面注释中指定的实体模型引用特定的模型类,并确保必要的注释:

@Entity(tableName = "<table_name>" ...)

是正确定义的,你会很好吗

在OP的情况下不是这样,但是当你错误地使用implementation而不是annotationProcessor时也会发生这种情况,就像这样:

implementation "android.arch.persistence.room:compiler:x.x.x"

而不是这样:

annotationProcessor "android.arch.persistence.room:compiler:x.x.x"

检查类上面的注释

@Database(entities = arrayOf(Schedule::class), version = 1)
abstract class AppDatabase : RoomDatabase() {
// ....
}