Room "Not sure how to convert a Cursor to this method's return type": which method?
Recently I've had the same problem but I was using Coroutines
within the Dao
function, e.g.:
@Query("SELECT * FROM Dummy")
suspend fun get(): LiveData<List<Dummy>>
And was unable to compile, but after removing the suspend
everything worked just fine. It's not needed when returning LiveData
. suspend
and LiveData
seem not to work together (as of now).
I Spend the entire day on this issue. the solution was very simple. I was using something like this before
@Query("SELECT * FROM myTable")
fun getAll(): MutableLiveData<ArrayList<myData>>
Now when I changed ArrayList to List & MutableLiveData to LiveData it is working fine.
@Query("SELECT * FROM myTable")
fun getAll(): LiveData<List<myData>>
based on the answers & comments on this issue I think room support only List & LiveData because I tried with on MutableLiveData & only ArrayList too. none of the combinations worked.
Hope this will help someones few hours.
Yup, based on what you have mentioned in the comments, you are not allowed to change the return type from List
to anything else inside the Dao
. I'd assume Room doesn't know how to deal with other return types. Take the List
and cast/convert it into your desired type outside of the Dao
.