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

标签 java android paging android-room android-architecture-components

我一直在尝试在 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/

相关文章:

android - 如何在 android 中使用 textView 进行页面 curl ?

java - App Engine 日志中的/_ah/queue/__deferred__

android - 我如何在 edittext 中为每个字符加下划线?

java - 在 Android 中处理命令而不启动 MainActivity

android - Robotium:请安装兼容的 Android API 级别(15 或更高)

windows - AMD64 页面条目基地址字段如何将 52 位地址编码为 40 位?

Java Dom问题

java - 分割字符串,记住分隔符并将其附加为空格

java - frame.setResizable(false) 不起作用

NHibernate 与 SQL Server 分页