Android房间:未生成通过@DatabaseView标记的视图

Android房间:未生成通过@DatabaseView标记的视图,android,android-room,androidx,Android,Android Room,Androidx,这是我的密码。我已经照解释的做了。通过@DATABASEVIEW创建视图标记(值=?,视图名称=?) 标记了房间数据库类中的视图 但当我查询针对生成过程中引发异常的视图的select时: 查询有问题:[SQLITE\u ERROR]SQL错误或缺少数据库(没有这样的表:USER\u RATE\u INFO\u VIEW 我研究了自动生成的数据库实现类,没有找到视图创建脚本。 我有同样的错误,只是解决了它。(我使用kotlin,所以您需要在java中相应地更改某些内容) 1.检查build.gr

这是我的密码。我已经照解释的做了。通过@DATABASEVIEW创建视图标记(值=?,视图名称=?) 标记了房间数据库类中的视图 但当我查询针对生成过程中引发异常的视图的select时: 查询有问题:[SQLITE\u ERROR]SQL错误或缺少数据库(没有这样的表:USER\u RATE\u INFO\u VIEW 我研究了自动生成的数据库实现类,没有找到视图创建脚本。


我有同样的错误,只是解决了它。(我使用kotlin,所以您需要在java中相应地更改某些内容)

1.检查build.gradle依赖项(其中有两个,一个显示在应用程序文件夹中的“Android”中,另一个显示在项目根文件夹中的“Project”中)

项目根/build.gradle我添加如下

app/build.gradle

2.检查使用@databaseview的DAO实现,尤其是返回类型 其中必须与查询视图结果列匹配

当我更改build.gradle时,该错误将成为使databaseview无法生成的实际错误

3.使缓存无效/重新启动android studio

我花了几个小时调试和解决这个错误,希望它能帮助你


(我不是英语国家的人,所以喜欢我的英语语法错误。哈哈哈)

有人在使用room组件吗?这里也有同样的问题,你找到解决这个问题的方法了吗?@StéphanePéchard我尝试过重命名类和清理构建。之后我没有看到这种错误
@Database(entities = {BankEntity.class, BankRateEntity.class, CommentEntity.class, ExchangeOfficeEntity.class,
        FBankEntity.class, FBankRateEntity.class, FRateEntity.class, RateByUserEntity.class,
        RateInfoEntity.class, UserEntity.class, UserMessageEntity.class, UserRateEntity.class},
        views = {BankRateView.class, ChatView.class, FBankRateView.class, RateInfoView.class, UserRateVew.class},
        version = 9)
public abstract class RoomDB extends RoomDatabase {
    private static RoomDB INSTANCE;

    public abstract RoomDao roomDao();

    public static RoomDB getDatabase(Context context) {
        if (INSTANCE == null) {
            INSTANCE =
                    Room.databaseBuilder(context.getApplicationContext(), RoomDB.class, "database.db")
                            // allow queries on the main thread.
                            // Don't do this on a real app! See PersistenceBasicSample for an example.
                            .allowMainThreadQueries()
                            .addMigrations(MIGRATION_1_2, MIGRATION_2_3, MIGRATION_3_4, MIGRATION_4_5, MIGRATION_5_6, MIGRATION_6_7, MIGRATION_7_8, MIGRATION_8_9)
                            .build();
        }
        return INSTANCE;
    }
}

@Getter
@Setter
@DatabaseView(value = TUserRate.VIEW_SQL_CMD, viewName = TUserRate.VIEW_NAME)
public class UserRateVew extends UserRateEntity{

    @ColumnInfo(name = TUserRate.COLUMN_USER_RATING)
    private float userRating;

}
ext.ktlintVersion = '0.30.0' in buildscript{}
plugins {
    id "com.diffplug.gradle.spotless" version "3.13.0"
}
spotless {
kotlin {
    target "**/*.kt"
    ktlint(ktlintVersion)
    }
}
compileOptions {
    sourceCompatibility JavaVersion.VERSION_1_8
    targetCompatibility JavaVersion.VERSION_1_8
} in android{}

following dependency seems must at top
kapt "androidx.room:room-compiler:2.1.0-beta01"
implementation 'androidx.core:core-ktx:1.0.2'

this one just below previous mention denpendency
implementation 'androidx.room:room-runtime:2.1.0-beta01'
implementation "androidx.lifecycle:lifecycle-common-java8:2.2.0-alpha01"

following at bottom but before androidTestImplementation; kotlin_version should be 1.3.31
implementation "org.jetbrains.kotlin:kotlin-stdlib-jdk8:$kotlin_version"
implementation "org.jetbrains.kotlinx:kotlinx-coroutines-android:1.1.1"
implementation "org.jetbrains.kotlinx:kotlinx-coroutines-core:1.1.1"