gpt4 book ai didi

java - collectionGroup() 不是公开的。无法从外部包访问

转载 作者:行者123 更新时间:2023-12-02 09:55:31 27 4
gpt4 key购买 nike

我想在 RecyclerView.ViewHolder 中使用 collectionGroup() 来查询 FirebaseFirestore 上的子集合,但收到一条错误消息:

'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 {

}

}
});
}
}

最佳答案

您收到以下错误:

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

因为在 Firestore 的早期版本中,FirebaseFirestore 的 collectionGroup(String collectionId)方法的定义没有修饰符,这意味着它只能在同一个类和同一个包中访问。

由于这两个条件都不满足,因此您可以在类或包外部访问该方法。因此,这意味着您没有使用最新版本。

从 2019 年 5 月 8 日开始,collectionGroup(String collectionId) 将公开,因此请将 Firestore 依赖项升级为:

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

您将能够使用该方法。

关于java - collectionGroup() 不是公开的。无法从外部包访问,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/56038101/

27 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com