[英]Not sure how to convert a Cursor to this method's return type in Room Android?
构建应用程序时出现以下错误
Not sure how to convert a Cursor to this method's return type (kotlinx.coroutines.flow.Flow<? extends java.util.List<com.notification.NotificationEntity>>)
这是我的实体类
@Entity
internal data class NotificationEntity(
@PrimaryKey @ColumnInfo(name = "notification_id") val notificationId: String,
val title: String,
val body: String?,
@ColumnInfo(name = "is_actionable") val isActionable: Boolean,
@ColumnInfo(name = "created_at") val createdAt: Instant,
@ColumnInfo(name = "is_read") val isRead: Boolean = false)
这是我的道课
@Dao
internal interface NotificationDao {
@Query("SELECT * FROM NotificationEntity ORDER BY created_at ASC")
suspend fun getAllNotifications(): Flow<List<NotificationEntity>>
@Insert(onConflict = OnConflictStrategy.REPLACE)
suspend fun saveNotification(notifications: List<NotificationEntity>)
}
有人可以帮助这里有什么问题吗?
当您声明返回Flow
的 Dao 函数时,该函数不应是可挂起的。 请参阅文档。
将您的代码更改为:
@Dao
internal interface NotificationDao {
@Query("SELECT * FROM NotificationEntity ORDER BY created_at ASC")
fun getAllNotifications(): Flow<List<NotificationEntity>>
@Insert(onConflict = OnConflictStrategy.REPLACE)
suspend fun saveNotification(notifications: List<NotificationEntity>)
}
如果尚未添加,则为 NotificationEntity 中使用的Instant
类型添加类型转换器。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.