gpt4 book ai didi

java - "Object"不是这个 Realm 的架构的一部分

转载 作者:太空宇宙 更新时间:2023-11-03 11:47:12 25 4
gpt4 key购买 nike

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

它抛出异常:这是错误

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 模型

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

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

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
}
}

渐变配置:

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"
}
}

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

最佳答案

gradle 文件中的问题。仅应用插件的排序规则的问题,感谢@EpicPandaForce 的评论,问题已解决,我正在写答案,以帮助其他人,如果他们错过了评论的答案来自@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'

就这样,现在一切正常

关于java - "Object"不是这个 Realm 的架构的一部分,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/42947367/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com