Room "Not sure how to convert a Cursor to this method's return type": which method? Room "Not sure how to convert a Cursor to this method's return type": which method? android android

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.


For anyone landing here, using a coroutine Flow as a return type, you will get this error if you accidentally make the function suspend. Since it is returning a flow, there is no need to suspend.

So instead of this:

@Query("SELECT * FROM myTable WHERE id = :id")suspend fun findById(id: Long): Flow<MyDataType>

use this (without suspend modifier):

@Query("SELECT * FROM myTable WHERE id = :id")fun findById(id: Long): Flow<MyDataType>