gpt4 book ai didi

android - 协程流程 : Not sure how to convert a Cursor to this method's return type

转载 作者:行者123 更新时间:2023-12-02 11:24:48 28 4
gpt4 key购买 nike

当我试图将 Dao 更改为新的 Flow Api,我收到编译错误,说明

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"

我都试过了 ListArrayList ,但没有运气。

提前致谢。

最佳答案

不要在同一个方法上同时使用 suspend 和 Flow<> !像这样

 @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>>

关于android - 协程流程 : Not sure how to convert a Cursor to this method's return type,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/59170415/

28 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com