gpt4 book ai didi

java - 分页编译问题: Not sure how to convert a Cursor to this method's return type

转载 作者:行者123 更新时间:2023-11-30 06:28:14 24 4
gpt4 key购买 nike

我一直在尝试在 Android 架构组件中使用 google 提供的 Room 实现分页库。但是它在我的 UserDao 类中显示编译时错误

这是错误:

Error:(22, 42) error: Not sure how to convert a Cursor to this method's return type

我的问题是返回类型是什么?

UserDao.java

@Dao
public interface UserDao {
@Query("SELECT * FROM user")
LiveData<List<User>> getAll();

//Compile Error is here : Not sure how to convert a Cursor to this method's return type
@Query("SELECT * FROM user")
LivePagedListProvider<Integer, User> userByPagination();

}

这里是UserModel.java

public class UserModel extends AndroidViewModel {

private final UserDao userDao;

public UserModel(Application application) {
super(application);
userDao = RoomDB.getDefaultInstance().userDao();
}

public LiveData<List<User>> getAllUser() {
return userDao.getAll();
}


public LiveData<PagedList<User>> getAllUserPagination() {
return userDao.userByPagination().create(
/* initial load position */ 0,
new PagedList.Config.Builder()
.setEnablePlaceholders(true)
.setPageSize(10)
.setPrefetchDistance(5)
.build());
}
}

我引用了以下示例:

Sample 1

Google Doc

我已经提出了这个问题HERE

如有任何帮助,我们将不胜感激

最佳答案

我通过将库更新到最新版本解决了该问题

    compile 'android.arch.persistence.room:runtime:1.0.0-beta2'
annotationProcessor 'android.arch.persistence.room:compiler:1.0.0-beta2'
compile 'android.arch.paging:runtime:1.0.0-alpha3'

compile 'android.arch.lifecycle:runtime:1.0.0-beta2'
compile 'android.arch.lifecycle:extensions:1.0.0-beta2'
annotationProcessor 'android.arch.lifecycle:compiler:1.0.0-beta2'

关于java - 分页编译问题: Not sure how to convert a Cursor to this method's return type,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/46668605/

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