我一直在尝试在 Android 架构组件中使用 google 提供的 Room 来实现分页库。但是它在我的中显示编译时错误UserDao
Class
这是错误:
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();
}
这里的用户模型.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 http://androidkt.com/paging-library/
谷歌文档 https://developer.android.com/topic/libraries/architecture/paging.html
我已提出问题HERE https://github.com/googlesamples/android-architecture-components/issues/198
任何帮助,将不胜感激
我通过将库更新到最新版本解决了该问题
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'
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)