致命的例外:主要
java.lang.IllegalArgumentException:
student_relam_pojo is not part of the schema for this Realm at io.realm.internal.modules.CompositeMediator.getMediator(CompositeMediator.java:118) at io.realm.internal.modules.CompositeMediator.getTableName(CompositeMediator.java:71) at io.realm.Realm.getTable(Realm.java:327)
at io.realm.Realm.createObject(Realm.java:1085)at example.com.kotlinexamplebydimple.RealmActivity$onCreate$1.onClick(RealmActivity.kt:24)
val realm = Realm.getInstance(this @ RealmActivity)
btn_click.setOnClickListener {
realm.beginTransaction()
var pojo : student_relam_pojo ?
pojo = realm.createObject(student_relam_pojo::class.java)
pojo.nm = edt_name.text.toString()
pojo.pass = edt_pass.text.toString()
realm.commitTransaction()
}
Student_realm_pojo
public open class student_relam_pojo() : RealmObject()
{
public open var nm : String ?= null
public open var pass : String ?= null
}
答案 0 :(得分:1)
1。)至少应使用Realm 2.3.0来可靠地使用KAPT
2。)您的插件订单应如下所示:
apply plugin: 'com.android.application'
apply plugin: 'kotlin-android'
apply plugin: 'kotlin-kapt'
apply plugin: 'realm-android'
3。)如果您使用的是库模块中定义的RealmObjects,则需要使用@RealmModule
在RealmConfiguration中明确指定它们,请参阅here。
4。)您可能已添加此类而不为其提供迁移。考虑提供迁移或设置deleteIfMigrationNeeded()
。