gpt4 book ai didi

java - DatabaseManager_Impl 不是抽象的,不会覆盖 RoomDatabase 中的抽象方法 clearAllTables()

转载 作者:IT老高 更新时间:2023-10-28 13:34:44 34 4
gpt4 key购买 nike

当我构建这段代码时,它显示构建错误:

DatabaseManager_Impl is not abstract and does not override abstract method clearAllTables() in RoomDatabase.

build.gradle:

implementation 'android.arch.persistence.room:runtime:1.0.0'
kapt 'android.arch.persistence.room:compiler:1.0.0'
implementation 'android.arch.persistence.room:rxjava2:1.0.0'
implementation 'android.arch.persistence.room:guava:1.1.0-beta3'

根据 Room 指南实现数据库:

@Database(entities = {Task.class}, version = 1)
public abstract class DatabaseManager extends RoomDatabase {
private static final String DATABASE =
Iterables.getLast(Splitter.on(".").trimResults().split(BuildConfig.APPLICATION_ID)).concat("-db");
private static volatile DatabaseManager instance;

public abstract TaskDao taskDao();

synchronized public static DatabaseManager onInstance(Context context) {
if (instance == null) {
instance = newInstance(context, false);
}
return instance;
}

public static DatabaseManager newInstance(Context context, boolean memoryOnly) {
RoomDatabase.Builder<DatabaseManager> builder;

if (memoryOnly) {
builder = Room.inMemoryDatabaseBuilder(context.getApplicationContext(), DatabaseManager.class);
} else {
builder = Room.databaseBuilder(context.getApplicationContext(), DatabaseManager.class, DATABASE);
}

return builder.fallbackToDestructiveMigration().build();
}

}

最佳答案

我有同样的问题并意识到

//room
implementation "android.arch.persistence.room:runtime:${arch_version}"
kapt "android.arch.persistence.room:compiler:${arch_version}"
implementation "android.arch.persistence.room:rxjava2:${arch_version}"

这些依赖项应该具有相同的版本。它们要么都是 1.0.0 要么是 1.1.0。不同的版本会出问题。

关于java - DatabaseManager_Impl 不是抽象的,不会覆盖 RoomDatabase 中的抽象方法 clearAllTables(),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/50084553/

34 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com