Update query with RxJava2 type return give an error: Not sure how to convert a Cursor to this method's return type
Update query with RxJava2 type return give an error: Not sure how to convert a Cursor to this method's return type
这是给出游标转换问题的代码片段:
@Query("UPDATE profile SET profilePicture=:newProfilePicture WHERE firstName = :first AND lastName = :last")
fun updateProfilePicture(
newProfilePicture: ByteArray,
first: String,
last: String
) : Completable
我尝试过的:
- 从查询中删除
lastName
和 return Single<String>
.
- Return
Single<List<String>>
- Return
Single<Void>
Gradle
def room_version = "2.2.5"
implementation "androidx.room:room-rxjava2:$room_version"
但是他们都没有用。
@Query methods: Room supports return values of type Publisher
, Flowable
, and Observable
.
如文档所述,查询方法支持的类型是:Publisher、Flowable 和 Observable。因此,首先要修复的是将 Completable 更改为受支持的类型之一。
修复后,生成的代码中仍然存在问题。我发现了一个 编译错误 ,因为预期的类型是 Integer
。所以我做的修复是我从 RxJava2 支持的类型更改为 Int
然后我把它包装成 Single
.
IMO 这只是一种解决方法。
这个问题是因为我使用的是:
kapt 'androidx.arch.persistence.room:compiler:1.1.1'
位于
kapt "androidx.room:room-compiler:$room_version"
这是给出游标转换问题的代码片段:
@Query("UPDATE profile SET profilePicture=:newProfilePicture WHERE firstName = :first AND lastName = :last")
fun updateProfilePicture(
newProfilePicture: ByteArray,
first: String,
last: String
) : Completable
我尝试过的:
- 从查询中删除
lastName
和 returnSingle<String>
. - Return
Single<List<String>>
- Return
Single<Void>
Gradle
def room_version = "2.2.5"
implementation "androidx.room:room-rxjava2:$room_version"
但是他们都没有用。
@Query methods: Room supports return values of type
Publisher
,Flowable
, andObservable
.
如文档所述,查询方法支持的类型是:Publisher、Flowable 和 Observable。因此,首先要修复的是将 Completable 更改为受支持的类型之一。
修复后,生成的代码中仍然存在问题。我发现了一个 编译错误 ,因为预期的类型是 Integer
。所以我做的修复是我从 RxJava2 支持的类型更改为 Int
然后我把它包装成 Single
.
IMO 这只是一种解决方法。
这个问题是因为我使用的是:
kapt 'androidx.arch.persistence.room:compiler:1.1.1'
位于
kapt "androidx.room:room-compiler:$room_version"