分页编译问题:不确定如何将游标转换为此方法的返回类型 [英] Paging Compile Issue : Not sure how to convert a Cursor to this method's return type

查看:369
本文介绍了分页编译问题:不确定如何将游标转换为此方法的返回类型的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我曾尝试在Android Architecture Component中实现由Google提供的带有Room的分页库.但是它在我的UserDao类中显示了编译时错误

I have been try to implemented the Paging Library with Room provided by google in Android Architecture Component.But its showing compile time error in my UserDao Class

这是错误:

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

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

My Question is what 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());
    }
}

我已参考以下示例:

示例1

Google文档

我提出了一个问题这里

任何帮助将不胜感激

推荐答案

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

I resolved the issue by updating the libraries to the latest version

    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'

这篇关于分页编译问题:不确定如何将游标转换为此方法的返回类型的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆