如何解决“对象不是该领域的模式的一部分"? [英] How to fix "Object is not part of the schema for this Realm"

查看:74
本文介绍了如何解决“对象不是该领域的模式的一部分"?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试建立一个使用Realm数据库的应用程序,但是我似乎无法使其正常运行.我也禁用了Instant Run,但这也不能解决问题.

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.

这是我的代码文件:

应用程序级别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'

这篇关于如何解决“对象不是该领域的模式的一部分"?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆