如何修复"Object is not part of the schema for this Realm"



我正在尝试设置一个使用Realm数据库的应用程序,但我似乎无法使其工作。我也禁用了Instant Run但这也没有解决问题。

这是我的代码文件:

App Level build.gradle

apply plugin: 'com.android.application'
apply plugin: 'kotlin-android-extensions' // <-- these two were the problem
apply plugin: 'kotlin-android'            // <--
apply plugin: 'com.google.gms.google-services'
apply plugin: 'realm-android'

项目级 build.gradle

dependencies{
    classpath 'com.android.tools.build:gradle:3.3.0'
    classpath 'com.google.gms:google-services:4.0.1'
    classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:$kotlin_version"
    classpath 'io.realm:realm-gradle-plugin:5.8.0'
}

我的模型类之一

public class ClothingItem extends RealmObject{
    private String mItemName;
    private RealmList<String> mItemTags;
    ....

我初始化 Realm 的应用程序类

public void onCreate(){
    super.oncreate();
    Realm.init(this);
    RealmConfiguration config = new RealmConfiguration.Builder()
            .deleteRealmIfMigrationNeeded()
            .name("MyOnlineWardrobe.realm")
            .build();
    Realm.setDefaultConfiguration(config);
}
apply plugin: 'com.android.application'
apply plugin: 'kotlin-android-extensions'
apply plugin: 'kotlin-android'
apply plugin: 'com.google.gms.google-services'
apply plugin: 'kotlin-kapt' // <---
apply plugin: 'realm-android'

相关内容

最新更新