Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Object is not part of the schema for this Realm in Kotlin

I have one open class like this

open class NewsResponse(

@field:SerializedName("news")
val news: List<NewsItem?>? = null
):RealmObject()

And NewsItem class like this

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()

I have also added

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'

these plugins in app gradle

I have classpath "io.realm:realm-gradle-plugin:5.1.0" in project level gradle. So when I run the app, I get an error saying

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)

How to solve this problem?

like image 863
theanilpaudel Avatar asked Jan 03 '23 09:01

theanilpaudel


1 Answers

Use this order:

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'
like image 175
EpicPandaForce Avatar answered Jan 04 '23 21:01

EpicPandaForce