How to fix “Object is not part of the schema for this Realm”

我是研究僧i 提交于 2019-12-11 08:14:25

问题


I'm trying to set up an application that uses the Realm database but I can't seem to make it work. I've also disabled Instant Run but that didn't solve the problem either.

Here are my code files:

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'

Project level 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'
}

One of my model classes

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

Application class where I initialize Realm

public void onCreate(){
    super.oncreate();
    Realm.init(this);
    RealmConfiguration config = new RealmConfiguration.Builder()
            .deleteRealmIfMigrationNeeded()
            .name("MyOnlineWardrobe.realm")
            .build();
    Realm.setDefaultConfiguration(config);
}

回答1:


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'


来源:https://stackoverflow.com/questions/54558333/how-to-fix-object-is-not-part-of-the-schema-for-this-realm

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!