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

后端 未结 20 1424
遇见更好的自我
遇见更好的自我 2020-12-14 14:15
Error:Not sure how to convert a Cursor to this method\'s return type
Error:Execution failed for task \':app:compileDebugJavaWithJavac\'.
Compilation failed; see the          


        
20条回答
  •  臣服心动
    2020-12-14 14:57

    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
    

    use this (without suspend modifier):

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

提交回复
热议问题