对象不是Kotlin中此Realm的架构的一部分

the*_*del 4 android realm kotlin kotlin-android-extensions android-ktx

我有一个像这样的公开课

open class NewsResponse(

@field:SerializedName("news")
val news: List<NewsItem?>? = null
):RealmObject()
Run Code Online (Sandbox Code Playgroud)

而NewsItem类就是这样的

open class NewsItem(

@field:SerializedName("created")
val created: String? = null,

@field:SerializedName("link")
val link: String? = null,

@field:SerializedName("description")
val description: String? = null,

@field:SerializedName("title")
val title: String? = null
):RealmObject()
Run Code Online (Sandbox Code Playgroud)

我还补充说

apply plugin: 'com.android.application'
apply plugin: 'kotlin-kapt'
apply plugin: 'realm-android'
apply plugin: 'kotlin-android'
apply plugin: 'io.fabric'
apply plugin: 'kotlin-android-extensions'
Run Code Online (Sandbox Code Playgroud)

这些插件在app gradle中

我有classpath "io.realm:realm-gradle-plugin:5.1.0"项目级别的gradle.因此,当我运行应用程序时,我收到错误消息

Caused by: io.realm.exceptions.RealmException: NewsItem is not part of the schema for this Realm
    at io.realm.internal.modules.CompositeMediator.getMediator(CompositeMediator.java:180)
Run Code Online (Sandbox Code Playgroud)

如何解决这个问题呢?

Epi*_*rce 6

使用此订单:

apply plugin: 'com.android.application'
apply plugin: 'kotlin-android'
apply plugin: 'kotlin-android-extensions'
apply plugin: 'kotlin-kapt'
apply plugin: 'realm-android'
apply plugin: 'io.fabric'
Run Code Online (Sandbox Code Playgroud)

  • 如果``kotlin-kapt`在`realm-android`之前应用,那么Realm将从`2.2.0`左右开始应用`kapt`范围 (2认同)