Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/android/216.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Android Firestore查询whereEqualTo与whereGreaterThan不工作_Android_Google Cloud Firestore - Fatal编程技术网

Android Firestore查询whereEqualTo与whereGreaterThan不工作

Android Firestore查询whereEqualTo与whereGreaterThan不工作,android,google-cloud-firestore,Android,Google Cloud Firestore,当我查询whereEqualTo和wheregreatethern时: productRef .whereGreaterThan("discount",0) .whereEqualTo("available", true) .whereEqualTo("shopId", Pref.getSelectedShopId(activity)) .a

当我查询
whereEqualTo
wheregreatethern
时:

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();
                        }
                    }
                }
            });
productRef
.其中大于(“折扣”,0)
.whereEqualTo(“可用”,真实)
.whereEqualTo(“shopId”,首选getSelectedShopId(活动))
.addSnapshotListener(新的EventListener(){
@凌驾
public void onEvent(@Nullable QuerySnapshot queryDocumentSnapshots,
@可为空的FireBaseFireStore异常(e){
对于(DocumentChange文档:queryDocumentSnapshots.getDocumentChanges()){
if(doc.getType()==DocumentChange.Type.ADDED){
Product Product=doc.getDocument().toObject(Product.class);
productList.add(产品);
设置数据(productList);
myAdapter.notifyDataSetChanged();
}
}
}
});
我得到了这个错误:

java.lang.NullPointerException:尝试对空对象引用调用虚拟方法“java.util.List com.google.firebase.firestore.QuerySnapshot.getDocumentChanges()”


如果没有复合索引,则不能在查询中放置具有不同字段的多个条件

您可以在官方文档中找到更多信息:


顺便说一句,firebase创建了一个链接来创建这些索引,通常可以在控制台(android情况下为logcat)中找到它。

您有用于此查询的复合索引吗?没有。我不使用