When I am trying to change the Dao to the new FlowApi, I am getting the compilation error stating that

Not sure how to convert a Cursor to this method's return type
    public abstract kotlinx.coroutines.flow.Flow<java.util.List<com.ezek.ezign.model.ECampaign>> readCampaigns();

刀是

@Dao
interface CampaignDao {

    @Query("SELECT * FROM campaign ORDER BY timeStamp ASC")
    fun readCampaigns(): Flow<List<ECampaign>>

    @Query("SELECT * FROM campaign WHERE id = :campaignId")
    fun readCampaign(campaignId: Int): Flow<ECampaign>
}

依赖关系是

    implementation 'org.jetbrains.kotlinx:kotlinx-coroutines-core:1.3.2'

    implementation "android.arch.persistence.room:runtime:$rootProject.ext.room_version"
    kapt "android.arch.persistence.room:compiler:$rootProject.ext.room_version"

//room_version = "2.1.0"

I have tried with Both List and ArrayList, but No luck.

Thanks in advance.

推荐答案

Do not use both suspend and Flow<> on the same method! Like this

 @Query("SELECT * FROM user")
    suspend fun loadAll(): Flow<Array<User>>

只是

@Query("SELECT * FROM user")
    suspend fun loadAll(): Array<User>

@Query("SELECT * FROM user")
   fun loadAll(): Flow<Array<User>>

Kotlin相关问答推荐

UByte范围. Min_UTE.. UByte.MAX_UTE不符合预期

只能在元素区域中点击的Jetpack Compose列

用A*搜索算法解决特修斯和米诺陶尔难题

在 Kotlin 中将 Array 转换为 IntArray 时丢失值

列表在 android WebView 中没有正确迭代

Kotlin SIZE_BYTES

Android Jetpack Compose:在空的 Compose 活动中找不到 OutlinedTextField (Material3)

Kotlin:我可以将函数分配给 main 的伴随对象中的变量吗?

如何处理基于枚举提前返回的 forEach 循环,Kotlin 中的一条路径除外

如何使用 Hilt 注入应用程序:ViewModel 中的上下文?

如何为 material.Slider 视图创建绑定适配器?

Kotlin:内部类如何访问在外部类中声明为参数的变量?

如何在 kotlin 中生成 json 对象?

kotlin-bom 库是做什么的?

禁用 IntelliJ kotlin * 导入?

如何捕获传递给模拟函数的参数并返回它?

spring.config.location 在 Spring Boot 2.0.0 M6 上不起作用

使用 rxbinding 时我应该取消订阅吗?

我应该在哪里调用 MobileAds.initialize()?

如何将 Kotlin 的 `with` 表达式用于可空类型