Burhanuddin Rashid
Burhanuddin Rashid

Reputation: 5370

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

Upvotes: 3

Views: 6818

Answers (3)

Ahmed Garhy
Ahmed Garhy

Reputation: 501

Use Version 2.3.0-alpha01

according to room release notes

Paging 3.0 Support: Room will now support generating implementations for@Query annotated methods whose return type is androidx.paging.PagingSource.

@Dao interface UserDao {
@Query("SELECT * FROM users ORDER BY id ASC")
   fun pagingSource(): PagingSource<Int, User>
}

Upvotes: 3

Rothnak SomAng
Rothnak SomAng

Reputation: 1

Try to use the following code:

@Query("select * from tbbook")
List<BookEntity> getBooks();

Do not try to change the return type. For example: ArrayList<BookEntity> getBooks();

Upvotes: -6

Burhanuddin Rashid
Burhanuddin Rashid

Reputation: 5370

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'

Upvotes: 3

Related Questions