android / architecture-components-samples

Samples for Android Architecture Components.
https://d.android.com/arch
Apache License 2.0
23.42k stars 8.29k forks source link

Paging : Not sure how to convert a Cursor to this method's return type #198

Closed burhanrashid52 closed 6 years ago

burhanrashid52 commented 6 years ago

I am getting error for LivePagedListProvider Return type while compiling

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

@Dao
public interface UserDao {
    @Query("SELECT * FROM user")
    public abstract LivePagedListProvider<Integer, User> getAllPagination();
}

How to resolve this issue i have setup everything correct as per the sample documentation

n0lik commented 6 years ago

Hello! Could you share all code?

burhanrashid52 commented 6 years ago

https://stackoverflow.com/questions/46668605/paging-compile-issue-not-sure-how-to-convert-a-cursor-to-this-methods-return I have asked this question with detail code @n0lik

burhanrashid52 commented 6 years ago

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'
krunalshah-insigmainc commented 5 years ago

I am using androidx room lib and it is up to date. Still I am facing same issue.

implementation 'androidx.room:room-runtime:2.1.0'

dlam commented 5 years ago

This is an issue from 2017

If you're using Paging 2.1, you should instead use DataSource.Factory, which room knows how to return, and pass that to a LivePagedListBuilder

See: https://github.com/googlesamples/android-architecture-components/blob/17c315a050745c61ae8e79000bc0251305bd148b/PagingSample/app/src/main/java/paging/android/example/com/pagingsample/CheeseDao.kt#L35

And its usage: https://github.com/googlesamples/android-architecture-components/blob/48974fce8c1bc1ff8542b44ae1761a2d9a80d8c0/PagingSample/app/src/main/java/paging/android/example/com/pagingsample/CheeseViewModel.kt#L34

Note that toLiveData is an extension method which simply calls into https://developer.android.com/reference/android/arch/paging/LivePagedListBuilder

liodali commented 4 years ago

i have the same problem with paging 3

shikoko commented 4 years ago

@liodali what room version are you using? Try using the latest one at the moment - 2.3.0-alpha02

liodali commented 4 years ago

i'm using version 2.2.5 for room and paging 3 alpha the build failed message : Not sure how to convert a Cursor to this method's return type androidx.paging.PagingSource

dlam commented 4 years ago

PagingSource was added in Room 2.3.0-alpha01+

chamellion commented 4 years ago

Check whether you are not trying to insert a list of objects into your DB, you will need to either embed, use a foreign key or declare the relationship in another table

lesniakania commented 3 years ago

This is a full list of dependencies that helped me:

def roomVersion = "2.3.0-alpha03"
    implementation "androidx.room:room-runtime:$roomVersion"
    kapt "androidx.room:room-runtime:$roomVersion"
    kapt "androidx.room:room-compiler:$roomVersion"

especially the part with

kapt "androidx.room:room-compiler:$roomVersion"