0

When I query whereEqualTo with whereGreaterThan :

productRef
            .whereGreaterThan("discount",0)
            .whereEqualTo("available", true)
            .whereEqualTo("shopId", Pref.getSelectedShopId(activity))
            .addSnapshotListener(new EventListener<QuerySnapshot>() {
                @Override
                public void onEvent(@Nullable QuerySnapshot queryDocumentSnapshots,
                                    @Nullable FirebaseFirestoreException e) {
                    for (DocumentChange doc : queryDocumentSnapshots.getDocumentChanges()) {
                        if (doc.getType() == DocumentChange.Type.ADDED) {
                            Product product = doc.getDocument().toObject(Product.class);
                            productList.add(product);
                            myAdapter.setData(productList);
                            myAdapter.notifyDataSetChanged();
                        }
                    }
                }
            });

I'm getting this error:

java.lang.NullPointerException: Attempt to invoke virtual method 'java.util.List com.google.firebase.firestore.QuerySnapshot.getDocumentChanges()' on a null object reference

Frank van Puffelen
  • 499,950
  • 69
  • 739
  • 734
Subair K
  • 1,611
  • 9
  • 26

1 Answers1

1

You cannot put multiple conditions with different fields in a query without a composite index.

You can find more info in the official documentation:
https://firebase.google.com/docs/firestore/query-data/index-overview
https://firebase.google.com/docs/firestore/query-data/indexing

BTW, firebase creates a link to create these indexes, usually, it can be found in console (logcat in android case)

sdex
  • 2,154
  • 12
  • 27