Home > Enterprise >  facing problems in Implementing pagination in firestore
facing problems in Implementing pagination in firestore

Time:09-28

I am trying to implement pagination in my app I have a lot of data in my Firestore and I want to implement pagination with a progress bar. I have read many documents but all are confusing and most of in Kotlin, I need them in java. Please guide me.

I found the following guide by Alex Memo Sir enter image description here

IT IS THROWING AN ERROR SIR HERE

    firebaseFirestore = FirebaseFirestore.getInstance();
       //HERE SIR COLLECTION REFENCE IS GIVING ME ERROR SAYING ClassCastException: com.google.firebase.firestore.Query cannot be cast to com.google.firebase.firestore.CollectionReference
        CollectionReference productsRef =  firebaseFirestore.collectionGroup("room_details");
    Query query = productsRef.orderBy("title", Query.Direction.ASCENDING).limit(limit);

CodePudding user response:

According to your last edit, you are getting the following error:

ClassCastException: com.google.firebase.firestore.Query cannot be cast to com.google.firebase.firestore.CollectionReference

Because you are trying to save an object of type Query into a variable of type CollectionReference at the following line of code:

CollectionReference productsRef =  firebaseFirestore.collectionGroup("room_details");

Which is actually not possible in Java. Why? Because the Query class, doesn't extend the CollectionReference, it's exactly vice versa, hence the error. Please note FirebaseFirestore#collectionGroup(String collectionId) method, returns an object of type Query and not CollectionReference. So to solve this, please change the above line of code to:

Query productsRef =  firebaseFirestore.collectionGroup("room_details");
//           
  • Related