"对象"不属于此Realm的架构 [英] "Object" is not part of the schema for this Realm

查看:708
本文介绍了"对象"不属于此Realm的架构的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

当我调用 realm.where(MessageEventModel :: class.java).findAll()

它会抛出异常:
这是错误

it throws excepiton: this is error

java.lang.IllegalArgumentException: MessageEventModel is not part of the schema for this Realm
                                                                          at io.realm.internal.modules.CompositeMediator.getMediator(CompositeMediator.java:172)
                                                                     at io.realm.internal.modules.CompositeMediator.getTableName(CompositeMediator.java:90)

这是我的申请类

class MyApp : Application() {

override fun onCreate() {
    super.onCreate()
    Realm.init(this)
    val realmConfiguration = RealmConfiguration.Builder()
            .deleteRealmIfMigrationNeeded()
            .name("my_db")
            .build()
    Realm.setDefaultConfiguration(realmConfiguration)
}
}

这是我的Realm模型

this is my Realm Model

class MessageEventModel : RealmObject{
  constructor()
  var message = ""
  constructor(message: String) : this(){
    this.message = message
  }
}

这里是我正在尝试检索模型的地方

And here is where I'm trying to retrieve models

class AwesomeChatFragment : Fragment() {

private val realm: Realm by lazy { Realm.getDefaultInstance() }
private var notifications: RealmResults<MessageEventModel>? = null

override fun onCreateView(inflater: LayoutInflater?, container: ViewGroup?, savedInstanceState: Bundle?): View? {
    val view = inflater?.inflate(R.layout.activity_awesome_chat, container, false)
    notifications = realm.where(MessageEventModel::class.java).findAll()
    return view
}
}

gradle配置:

apply plugin: 'com.android.application'
apply plugin: 'realm-android'
apply plugin: 'kotlin-android'
apply plugin: 'kotlin-android-extensions'


buildscript {
    ext.kotlin_version = '1.1.1'
    repositories {
        jcenter()
    }
    dependencies {
        classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:$kotlin_version"
        classpath 'com.android.tools.build:gradle:2.3.0'
        classpath 'com.google.gms:google-services:3.0.0'
        classpath "io.realm:realm-gradle-plugin:3.0.0"
    }
}

我尝试了在堆栈上找到的所有东西:
<海峡ong>清理构建,重建项目,启用注释处理器,重新安装apk,使缓存无效/重新启动

I tried everything what I could found on stack: clean build, rebuild project, enable annotation processor, reinstaling apk, invalidate caches / restart

推荐答案

问题gradle文件中的地方。只是一个应用插件的排序规则的问题,感谢@ EpicPandaForce的评论,问题已经解决,我正在写答案,帮助其他人,如果他们错过@EpicPandaForce的评论答案

The issue where in gradle file.The problem where just an ordering rules of applying plugins, thanks to the @EpicPandaForce's comment, the problem has been solved, I'm writing answer, for helping others, if they miss the commented answer from @EpicPandaForce

我改变了

apply plugin: 'com.android.application'
apply plugin: 'realm-android'
apply plugin: 'kotlin-android'
apply plugin: 'kotlin-android-extensions'

apply plugin: 'com.android.application'
apply plugin: 'kotlin-android'
apply plugin: 'kotlin-android-extensions'
apply plugin: 'realm-android'

这就是全部,现在一切正常

That's all, now everything works fine

这篇关于&QUOT;对象&QUOT;不属于此Realm的架构的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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