gpt4 book ai didi

android - 分页3 : "Not sure how to convert a Cursor to this method' s return type"when using PagingSource as return type in Room DAO

转载 作者:行者123 更新时间:2023-12-03 13:25:01 34 4
gpt4 key购买 nike

我试图为新的 Paging 3 库模仿 Google 的 codelab,当我尝试让 Room DAO 方法返回 PagingSource 时遇到以下错误:

D:\Programming\Android\something\app\build\tmp\kapt3\stubs\debug\com\someapp\something\data\db\UsersDao.java:38: error: Not sure how to convert a Cursor to this method's return type (androidx.paging.PagingSource<java.lang.Integer,com.someapp.something.data.db.GithubUser>).
public abstract androidx.paging.PagingSource<java.lang.Integer, com.someapp.something.data.db.GithubUser> getUserByUserName(@org.jetbrains.annotations.NotNull()

^D:\Programming\Android\something\app\build\tmp\kapt3\stubs\debug\com\someapp\something\data\db\UsersDao.java:43: error: Not sure how to convert a Cursor to this method's return type (androidx.paging.PagingSource<java.lang.Integer,com.someapp.something.data.db.GithubUser>).
public abstract androidx.paging.PagingSource<java.lang.Integer, com.someapp.something.data.db.GithubUser> getUserByNote(@org.jetbrains.annotations.NotNull()
这是我的 UsersDao.kt :
@Dao
interface UsersDao {

@Insert
fun insert(user: GithubUser): Completable

@Insert
fun insert(userList: List<GithubUser>): Completable

@Query("DELETE FROM userDb")
fun clearDb(): Completable

@Query("SELECT * FROM userDb")
fun getAllUsers(): Single<List<GithubUser>>

@Query("SELECT EXISTS(SELECT 1 FROM userDb WHERE username LIKE :userName)")
fun checkIfUserExists(userName: String): Boolean

@Query("SELECT note FROM userDb WHERE username LIKE :userName")
fun getNoteByUserName(userName: String): Single<String>

@Query("SELECT * FROM userDb WHERE username LIKE :userName")
fun getUserByUserName(userName: String): PagingSource<Int, GithubUser>

@Query("SELECT * FROM userDb WHERE note LIKE :note")
fun getUserByNote(note: String): PagingSource<Int, GithubUser>

}
我的 GithubUser.kt看起来像这样:
@Entity(tableName = "userDb", indices = arrayOf(Index(value = ["username"],  unique = true)))
class GithubUser (
var username: String,
var note: String,
var url: String,
var avatarUrl: String
) {
@PrimaryKey(autoGenerate = true)
var uid = 0
}
code对于 Paging Codelab,DAO 方法只返回一个 PagingSource在 Gradle 或其他任何东西中没有额外的注释/魔术选项。我还查看了来自 Github 的其他示例,例如 thisthis使用 Paging 3 库,它们只返回 PagingSource完全没有问题。如果我错过了什么,谁能告诉我?
注意 : 在错误本身之前,我总是收到关于 ANTLR Tool version 4.5.3 used for code generation does not match the current runtime version 4.7.1 的警告。 ,但是这个警告本身在过去并没有引起任何问题,但我在这里注明以防万一。
编辑 :我使用以下 Room/Paging lib 版本:
    implementation "androidx.room:room-runtime:2.2.5"
kapt "androidx.room:room-compiler:2.2.5"
implementation 'androidx.room:room-rxjava2:2.2.5'

implementation "androidx.paging:paging-runtime:3.0.0-alpha03"
implementation 'androidx.paging:paging-rxjava2:3.0.0-alpha03'

最佳答案

原来需要将Room版本增加到2.3.0-alpha02或以上:

implementation "androidx.room:room-runtime:2.3.0-alpha02"
implementation "androidx.room:room-ktx:2.3.0-alpha02"
kapt "androidx.room:room-compiler:2.3.0-alpha02"

关于android - 分页3 : "Not sure how to convert a Cursor to this method' s return type"when using PagingSource as return type in Room DAO,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/63373069/

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