kotlin realm demo canot be run -
kotlin version 1.0.0,realm version 0.88.0-snapshot download realm kotlin demo ,and run if code this:
var person = person() person.id = 1 person.name = "young person" person.age = 14 realm.begintransaction() realm.copytorealm(person) realm.committransaction()
throw exception: caused by: java.lang.classcastexception: io.realm.examples.kotlin.model.person cannot cast io.realm.personrealmproxyinterface
else change code this:
realm.begintransaction() // add person var person = realm.createobject(person::class.java) person.id = 1 person.name = "young person" person.age = 14 // when transaction committed, changes synced disk. realm.committransaction()
then realm insert data person.name ,id,age empty value or 0;
how solve it
with realm 0.88.0-snapshot have use gradle plugin well. if google exception (realm java.lang.classcastexception proxyinterface
) find github issue - 2353 says:
we merged our byte code weaver master, , sounds isn't being triggered in case. note 0.88.0-snapshot have use our gradle plugin: https://realm.io/news/android-installation-change/
previously install realm like:
repositories { jcenter() } dependencies { compile 'io.realm:realm-android:<version>' }
now must install include gradle plugin:
buildscript { repositories { jcenter() } dependencies { classpath "io.realm:realm-gradle-plugin:<version>" } } apply plugin: 'realm-android'
so byte code weaving turned on. without this, receive error first use case (which correct code, snapshot release chose use, needed step of gradle plugin). there other important notes in link above, along release notes changes in recent versions of realm.
Comments
Post a Comment