gpt4 book ai didi

java - FireStore 数据未显示正在访问隐藏方法 Lsun/misc/Unsafe;->putLong(Ljava/lang/Object;JJ)V(灰名单、链接、允许)

转载 作者:行者123 更新时间:2023-12-04 14:57:38 25 4
gpt4 key购买 nike

当我尝试使用 FirestoreRecyclerAdapter 从 Firestore 检索数据时,它没有显示。

错误日志

Accessing hidden method Lsun/misc/Unsafe;->getInt(Ljava/lang/Object;J)I (greylist, linking, allowed)

Accessing hidden method Lsun/misc/Unsafe;->getObject(Ljava/lang/Object;J)Ljava/lang/Object; (greylist, linking, allowed)

Java 代码

    //FirebaseFireStore Variable
firebaseFirestore = FirebaseFirestore.getInstance();
//RecyclerView Variable
recyclerView = findViewById(R.id.recyclerViewId);
//Query
Query query = firebaseFirestore.collection("root");
//RecyclerOption
FirestoreRecyclerOptions<TestModel> options = new FirestoreRecyclerOptions.Builder<TestModel>()
.setQuery(query, TestModel.class)
.build();
//FirestoreRecyclerAdapter
adapter = new FirestoreRecyclerAdapter<TestModel, MyTestViewHolder>(options) {
@NonNull
@Override
public MyTestViewHolder onCreateViewHolder(@NonNull ViewGroup parent, int viewType) {
View view = LayoutInflater.from(parent.getContext()).inflate(R.layout.test_item, parent, false);
return new MyTestViewHolder(view);
}
@Override
protected void onBindViewHolder(@NonNull TestActivity.MyTestViewHolder holder, int position, @NonNull TestModel model) {
holder.tit.setText(model.getmTitle());
holder.sto.setText(model.getmStory());
}
};
recyclerView.setHasFixedSize(true);
recyclerView.setLayoutManager(new LinearLayoutManager(this));
recyclerView.setAdapter(adapter);
}
private class MyTestViewHolder extends RecyclerView.ViewHolder {
TextView tit, sto;
public MyTestViewHolder(@NonNull View itemView) {
super(itemView);
tit = itemView.findViewById(R.id.testTitleId);
sto = itemView.findViewById(R.id.testStoryId);
}
}
@Override
protected void onStart() {
super.onStart();
adapter.startListening();
}
@Override
protected void onStop() {
super.onStop();
adapter.stopListening();
}

模型类

 String mTitle, mStory;

public TestModel(String mTitle, String mStory) {
this.mTitle = mTitle;
this.mStory = mStory;
}

private TestModel(){}

public String getmTitle() {
return mTitle;
}

public void setmTitle(String mTitle) {
this.mTitle = mTitle;
}

public String getmStory() {
return mStory;
}

public void setmStory(String mStory) {
this.mStory = mStory;
}

FireStore Concole

Image

最佳答案

当您尝试将 Firestore 中的文档映射到“TestModel”类型的对象时,类中存在的字段名称必须与数据库中存在的属性名称相匹配。不幸的是,在您的情况下,这些字段不匹配。你看,数据库中的字段称为“故事”和“标题”,而在类中称为“mStory”和“mTitle”,这是正确的。

要解决这个问题,您有两个选择,您可以更改数据库中属性的名称以匹配类中的名称,或者您可以在 getter 前面使用注释。例如,对于“mTitle”字段,您的 getter 应如下所示:

@PropertyName("title")
public String getTitle() {
return mTitle;
}

通过这种方式,您告诉编译器查找名为“title”而不是“mTitle”的属性。

关于java - FireStore 数据未显示正在访问隐藏方法 Lsun/misc/Unsafe;->putLong(Ljava/lang/Object;JJ)V(灰名单、链接、允许),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/67657356/

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