简体   繁体   English

Recyclerview 适配器:java.util.ArrayList 无法强制转换为 com.google.ZBF12E1525C25C7AB9A15com.google.ZBF12E1525C25C7AB9A15Z.firestore.F1413SnapshotA15查询

[英]Recyclerview Adapter: java.util.ArrayList cannot be cast to com.google.firebase.firestore.QuerySnapshot

I'm fairly new and I'm not familiar with using recyclerview adapter.我相当新,我不熟悉使用 recyclerview 适配器。 I have this method to to load the data into the recyclerview adapter.我有这种方法可以将数据加载到 recyclerview 适配器中。 The data will be filtered using merged queries.将使用合并查询过滤数据。 However the app crashed and I got java.lang.ClassCastException: java.util.ArrayList cannot be cast to com.google.firebase.firestore.QuerySnapshot. However the app crashed and I got java.lang.ClassCastException: java.util.ArrayList cannot be cast to com.google.firebase.firestore.QuerySnapshot. Does anyone know how to fix this?有谁知道如何解决这一问题?

private void loadData(){

        if(modelArrayList.size()>0)
            modelArrayList.clear();

        storageReference = FirebaseStorage.getInstance().getReference();
        Query query = collectionReference.whereArrayContains("pet", pettype);
        Query query2 = collectionReference.whereArrayContains("service", "Pet Sitting");
        Query query3 = collectionReference.whereArrayContains("petnum", petnumber);
        Query query4 = collectionReference.whereArrayContains("region", reg);
        Query query5 = collectionReference.whereArrayContains("subregion", subreg);

        Task task = query.get();
        Task task2 = query2.get();
        Task task3 = query3.get();
        Task task4 = query4.get();
        Task task5 = query5.get();

        Task combinedtask = Tasks.whenAllSuccess(task, task2, task3, task4, task5);

        combinedtask.addOnCompleteListener(new OnCompleteListener<QuerySnapshot>() {
            @Override
            public void onComplete(@NonNull Task<QuerySnapshot> task) {
                for(DocumentSnapshot querySnapshot: task.getResult()){
                    model model = new model(querySnapshot.getString("firstname"),
                            querySnapshot.getString("lastname"),
                            querySnapshot.getString("description"),
                            querySnapshot.getString("userID"));

                    modelArrayList.add(model);
                }
                adapter = new My_recyclerview_adapter(Pet_sitting_result.this, modelArrayList);
                recycler_view.setAdapter(adapter);
            }
        }).addOnFailureListener(new OnFailureListener() {
            @Override
            public void onFailure(@NonNull Exception e) {
                Toast.makeText(Pet_sitting_result.this, "Error", Toast.LENGTH_SHORT);
            }
        });
    }

Since your combinedTask is a result of several other Tasks, it is going to yield an List objects as a result, not a QuerySnapshot .由于您的combinedTask是其他几个任务的结果,因此它将产生一个List对象,而不是QuerySnapshot So, your success callback should declare that it accepts a List<Task<?>> instead of a Task<QuerySnapshot> .因此,您的成功回调应该声明它接受List<Task<?>>而不是Task<QuerySnapshot> There will be one item the list for each task you passed to whenAllSuccess() .您传递给whenAllSuccess()的每个任务的列表中都会有一项。 You will have to write code to pull the individual snapshots for each query out of the list and deal with them each separately as needed.您必须编写代码将每个查询的单个快照从列表中拉出,并根据需要分别处理它们。

You might want to familiarize yourself more with the Tasks API that you're using here and also study the API documentation for Tasks.whenAll() .您可能想进一步熟悉您在此处使用的任务 API并研究有关Tasks.whenAll()的 API 文档。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 java.util.ArrayList无法转换为 - java.util.ArrayList cannot be cast to 无法转换为java.util.ArrayList - Cannot be cast to java.util.ArrayList JSONArray无法转换为java.util.ArrayList - JSONArray cannot be cast to java.util.ArrayList java.util.ArrayList无法转换为java.util.Vector - java.util.ArrayList cannot be cast to java.util.Vector 无法将java.util.HashMap强制转换为java.util.ArrayList - java.util.HashMap cannot be cast to java.util.ArrayList java.lang.ClassCastException:无法将java.util.ArrayList强制转换为com.inrev.crm.bean.IRSurveyQuestions - java.lang.ClassCastException: java.util.ArrayList cannot be cast to com.inrev.crm.bean.IRSurveyQuestions java.lang.ClassCastException:com.mongodb.client.internal.AggregateIterableImpl 无法转换为 java.util.ArrayList - java.lang.ClassCastException: com.mongodb.client.internal.AggregateIterableImpl cannot be cast to java.util.ArrayList ArrayList无法转换为java.util.ArrayList,toArray不会返回任何内容 - ArrayList cannot be cast to java.util.ArrayList, toArray returns nothing java.lang.ClassCastException: java.util.ArrayList 不能转换为 com.parse.ParseObject - java.lang.ClassCastException: java.util.ArrayList cannot be cast to com.parse.ParseObject java.util.ArrayList 无法转换为 com.android.billingclient.api.SkuDetails - java.util.ArrayList cannot be cast to com.android.billingclient.api.SkuDetails
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM