Search code examples
javaandroidandroid-roomandroid-architecture-componentsandroid-paging-library

Paging Compile Issue : Not sure how to convert a Cursor to this method's return type


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

Here is the Error:

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();

}

Here the 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());
    }
}

I have refer the following sample:

Sample 1

Google Doc

I have raised the issue HERE

Any help would be appreciated


Solution

  • 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'