0

firestore クエリ "whereEqualTo" の使用に問題があります。「参加者」というコレクションから画像を取得しようとしていますが、ドキュメントが存在しない場合は、else ステートメントを使用して、ドキュメントが更新される次のアクティビティに移動する必要があります。しかし、onComplete リスナー、つまり Task でコレクションからドキュメントをクエリすると、ドキュメントは終了しませんが、コードは if(task.isSuccessful){} に実行され、else ステートメントは使用されません。私のコード:誰でもこのおかげで私を助けてくれますか

 //***********BattlePost1**************

        mFirestore.collection("OpenBattle")
                .document(battlesPost_creator)
                .collection("BattlePost")
                .document(battlePost_id)
                .collection("Participants")
                .document(UserId)
                .collection("Posts").whereEqualTo("battle_post_count", 1)
                .get().addOnCompleteListener(new OnCompleteListener<QuerySnapshot>() {
            @Override
            public void onComplete(@NonNull Task<QuerySnapshot> task) {
                if (task.isSuccessful()){
                    for (QueryDocumentSnapshot document : task.getResult()){
                        Glide.with(mContext).load(document.get("imageuri")).into(battle_creator_postImage1);
                        battle_points1.setText(String.valueOf(document.get("numberOfLikesPoints")) + "Points");
                    }

                }else {
                    Log.d(TAG, "onComplete: Error getting the first document");
                }
            }
        });

        //**************BattlePost2***************

        mFirestore.collection("OpenBattle")
                .document(battlesPost_creator)
                .collection("BattlePost")
                .document(battlePost_id)
                .collection("Participants")
                .document(UserId)
                .collection("Posts")
                .whereEqualTo("battle_post_count", 2)
                .get().addOnCompleteListener(new OnCompleteListener<QuerySnapshot>() {
            @Override
            public void onComplete(@NonNull Task<QuerySnapshot> task) {
                if (task.isSuccessful()) {
                    for (QueryDocumentSnapshot document : task.getResult()) {
                        Log.d(TAG, document.getId() + " => " + document.getData());
                        Glide.with(mContext).load(document.get("imageuri")).into(battle_creator_postImage2);
                        battle_points2.setText(String.valueOf(document.get("numberOfLikesPoints")) + "Points");
                    }
                } else {
                    Log.d(TAG, "Error getting documents: ", task.getException());
                    //Can create a 2nd post
                    Glide.with(mContext).load(R.drawable.ic_add_circle_black_24dp).into(battle_creator_postImage2);
                    battle_creator_postImage2.setOnClickListener(new View.OnClickListener() {
                        @Override
                        public void onClick(View view) {
                            Intent intent = new Intent(mContext, TemplateActivity.class);
                            intent.putExtra(getString(R.string.battle_add_post),battlePost_id);
                            intent.putExtra("BattlePost_Pub", battlesPost_creator);
                            intent.putExtra("Battle_contest", 2);
                            intent.putExtra("Battle_tittle", battle_tittle);
                            intent.putExtra("Battle_timeEnd", battle_timeEnd);
                            startActivity(intent);
                        }
                    });
                }
            }
        });

ここに画像の説明を入力

4

1 に答える 1