Empty schema Realm object using Kotlin


#1

I am using the code from the Kotlin example on GitHub (https://github.com/realm/realm-java/tree/master/examples/kotlinExample) and keep seeing this exception: io.realm.exceptions.RealmException: Person is not part of the schema for this Realm

I pulled the Realm (default.realm) off of my phone, and saw that it was completely empty (“This Realm has no classes defined”) in Realm Studio.

Looking at the Realm documentation located at https://realm.io/docs/java/latest/#getting-started, I read that “The default schema for a Realm is simply all the Realm model classes in a project.” As the sample code didn’t specify a custom schema, I would think it would do as the documentation suggests and add all classes that extend from RealmObject. That doesn’t seem to be the case.

Is the documentation misleading here or is there something amiss with that sample maybe?


#2

The root cause was that kotlin-kapt plugin wasn’t in the gradle file. Once that was added, the code worked fine.