我想在collectionGroup()
内使用RecyclerView.ViewHolder
来查询我的FirebaseFirestore
上的子集合,但出现错误消息:
'collectionGroup(java.lang.String)'在以下位置不公开 “ com.google.firebase.firestore.FirebaseFirestore”。无法访问 从外部包装
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 {
}
}
});
}
}
答案 0 :(得分:1)
您遇到以下错误:
'collectionGroup(java.lang.String)'在'com.google.firebase.firestore.FirebaseFirestore'中不公开。无法从外部软件包访问
由于在早期版本的Firestore中,FirebaseFirestore的collectionGroup(String collectionId)方法没有定义修饰符,因此只能在同一类和同一包中访问。
由于这两个条件均未满足,因此您可以在类或包之外访问该方法。因此,这意味着您不使用最新版本。
从2019年5月8日开始,collectionGroup(String collectionId)
被公开,因此请将Firestore依赖项升级为:
implementation 'com.google.firebase:firebase-firestore:19.0.0'
您将可以使用该方法。