分页编译问题:不确定如何将 Cursor 转换为此方法的 return 类型
Paging Compile Issue : Not sure how to convert a Cursor to this method's return type
我已经尝试在 Android 架构 Component.But 中使用 google 提供的 Room 实现分页库 Component.But 它在我的 UserDao
[=46] 中显示编译时错误=]
这是错误:
Error:(22, 42) error: Not sure how to convert a Cursor to this method's return type
我的问题是 return 类型是什么?
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());
}
}
我参考了下面的例子:
我已经提出问题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'
尝试使用以下代码:
@Query("select * from tbbook")
List<BookEntity> getBooks();
不要尝试更改 return 类型。例如:ArrayList<BookEntity> getBooks();
使用版本 2.3.0-alpha01
根据房间发行说明
Paging 3.0 支持:Room 现在将支持为 return 类型为 androidx.paging.PagingSource.
的@Query 注释方法生成实现
@Dao interface UserDao {
@Query("SELECT * FROM users ORDER BY id ASC")
fun pagingSource(): PagingSource<Int, User>
}
我已经尝试在 Android 架构 Component.But 中使用 google 提供的 Room 实现分页库 Component.But 它在我的 UserDao
[=46] 中显示编译时错误=]
这是错误:
Error:(22, 42) error: Not sure how to convert a Cursor to this method's return type
我的问题是 return 类型是什么?
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());
}
}
我参考了下面的例子:
我已经提出问题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'
尝试使用以下代码:
@Query("select * from tbbook")
List<BookEntity> getBooks();
不要尝试更改 return 类型。例如:ArrayList<BookEntity> getBooks();
使用版本 2.3.0-alpha01
根据房间发行说明
Paging 3.0 支持:Room 现在将支持为 return 类型为 androidx.paging.PagingSource.
的@Query 注释方法生成实现@Dao interface UserDao {
@Query("SELECT * FROM users ORDER BY id ASC")
fun pagingSource(): PagingSource<Int, User>
}