Reputation: 349
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 {
}
}
});
}
}
Upvotes: 1
Views: 1130
Reputation: 138989
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.
Upvotes: 2