Kotlin + Room : java.lang.IllegalArgumentException: void cannot be converted to an Element

走远了吗. 提交于 2019-12-05 19:40:40

Maaan! What a silly mistake! In abstract RoomDatabase class, we need to declare the abstract fun returning the Dao object but I had defined abstract var there.

So changing

abstract var cartRepositoryImpl: CartRepositoryImpl

to:

abstract fun cartRepositoryImpl(): CartRepositoryImpl

fixed the compilation error! I overlooked this while following the stuff from a blog I admit, but still the better compile time error wouldn't have hurt!

Try this

annotationProcessor "android.arch.persistence.room:compiler:1.0.0"

instead of

kapt "android.arch.persistence.room:compiler:1.0.0"

I run into same exception when my database definition implemented Closeable interface. It required empty override to pass that:

override fun close() {
    super.close()
}

In my case, I have added a function in the Dao layer which having no Table in it.

Mistake:

@Dao
interface ProductDao {

    @Insert
    fun insert(product: Int) // Here Int can't save in Room DB
}

This worked for me:

@Dao
interface ProductDao {

    @Insert
    fun insert(product: Product) // Here I added table instead Int
}

in my case In Database Abstract class I changed var to val. like below :

 abstract var noteDao: NoteDao

to this :

abstract val noteDao: NoteDao

and worked for me.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!