vicpinm / Kotlin-Realm-Extensions

Kotlin extensions to simplify Realm API.
Apache License 2.0
535 stars 53 forks source link

Query throws exeption #49

Closed uypanha closed 6 years ago

uypanha commented 6 years ago

Am I missing something? thanks :)

CartModel().queryFirst { it.equalsTo("_ID", 1) } Method threw 'java.lang.ClassNotFoundException' exception.

this is my class open class CartModel( @PrimaryKey open var _ID: Int = 0, open var qty: Int = 0, open var foodTitle: String = "", open var foodDes: String = "", open var price: String = "", open var previewURL: String = "" ) : RealmObject() { fun copy( _ID: Int = this._ID, qty: Int = this.qty, foodTitle: String = this.foodTitle, foodDes: String = this.foodDes, price: String = this.price, previewURL: String = this.previewURL ) = CartModel(_ID, qty, foodTitle, foodDes, price, previewURL) }

vicpinm commented 6 years ago

Hi @uyphanha, with the information you have provided, I cant help you with your problem. If you are using last library version, you shouldn't use 'it' inside your lambda, just do: CartModel().queryFirst { equalsTo("_ID", 1) }

And make sure your realm version and library version match.

uypanha commented 6 years ago

I've fixed it, just changed it from CartModel().queryFirst { it.equalsTo("_ID", 1) } to CartModel().queryFirst { query -> query.equalsTo("_ID", 1) } and it works