1

I want to use collectionGroup() inside a RecyclerView.ViewHolder to query a subcollection on my FirebaseFirestore and I get an error saying:

'collectionGroup(java.lang.String)' is not public in 'com.google.firebase.firestore.FirebaseFirestore'. Cannot be accessed from outside package

class WallHolder extends RecyclerView.ViewHolder {

        private LinearLayout root, llp, image_layout;
        private RelativeLayout rlp;
        private TextView comment, tv_due, tv_pass;
        private Button btn_play;
        private SeekBar seekBar;
        private ImageView imageView[] = new ImageView[3];

        public WallHolder(@NonNull View itemView) {
            super(itemView);

            root = itemView.findViewById(R.id.list_root);

            llp = root.findViewById(R.id.llp);
            rlp = root.findViewById(R.id.rlp);
            comment = root.findViewById(R.id.tv_cmt);
            image_layout = root.findViewById(R.id.img_layout);

            btn_play = llp.findViewById(R.id.btn_play);

            tv_due = rlp.findViewById(R.id.tv_due);
            tv_pass = rlp.findViewById(R.id.tv_pass);
            seekBar = rlp.findViewById(R.id.seek_bar);

            imageView[0] = image_layout.findViewById(R.id.img_1);
            imageView[1] = image_layout.findViewById(R.id.img_2);
            imageView[2] = image_layout.findViewById(R.id.img_3);
        }


        void setData(final Map<String, Object> post) {

            FirebaseFirestore db = FirebaseFirestore.getInstance();
            final StorageReference storageRef = FirebaseStorage.getInstance().getReference();


            //This is where i get the error
            //db.collectionGroup()
            //


            //This code wasn't working so i want to replace it with the code above
            db.collection("Post")
                    //.document(post.get("post_Id").toString())
                    .document("mnk2EqrVmm3upTFYL4eB")
                    .collection("Post_Images")
                    .get().addOnCompleteListener(new OnCompleteListener<QuerySnapshot>() {
                        @Override
                        public void onComplete(@NonNull Task<QuerySnapshot> task) {

                            if (task.isSuccessful()) {
                                final List<Bitmap> list = new ArrayList<>();
                                Toast.makeText(WallActivity.this, String.valueOf(task.getResult().size()), Toast.LENGTH_SHORT).show();

                                for (QueryDocumentSnapshot document : task.getResult()){

                                }
                            } else {

                            }

                        }
                    });
        }
    }
Alex Mamo
  • 130,605
  • 17
  • 163
  • 193
T double
  • 349
  • 3
  • 12

1 Answers1

2

You are getting the following error:

'collectionGroup(java.lang.String)' is not public in 'com.google.firebase.firestore.FirebaseFirestore'. Cannot be accessed from outside package

Because in the earlier versions of Firestore, FirebaseFirestore's collectionGroup(String collectionId) method was defined with no modifier, which means that is only accessible within the same class and within the same package.

Since none of those two conditions is fulfilled, you could access that method outside the class or package. So it means that you are not using the latest version.

Starting with May 8th, 2019, the collectionGroup(String collectionId) is made public, so please your upgrade Firestore dependency to:

implementation 'com.google.firebase:firebase-firestore:19.0.0'

And you'll be able to use that method.

Alex Mamo
  • 130,605
  • 17
  • 163
  • 193
  • This doesn't work for sub collections. See https://stackoverflow.com/questions/46573014/firestore-query-subcollections – T double May 08 '19 at 10:50
  • Plus in the documentation collectionGroup() is public, See https://firebase.google.com/docs/reference/android/com/google/firebase/firestore/FirebaseFirestore.html#public-querycollectiongroupstring-collectionid – T double May 08 '19 at 11:13
  • Well i moved all my subcollections to top level collections instead. thanks – T double May 09 '19 at 11:12
  • Ok but it has nothing to do with your question. The error that you got was because you were using an old version for your Firebase Firestore dependency. – Alex Mamo May 09 '19 at 11:19
  • On Firestore website the latest api version is 18.2.0. when did they release 19.0.0 – T double May 10 '19 at 09:28
  • I don't know where you saw that, but [here](https://firebase.google.com/support/release-notes/android) is the official documentation. See, `com.google.firebase:firebase-firestore:19.0.0`? Maybe in some other docs is not still updated but you can count on this link. – Alex Mamo May 10 '19 at 09:32