FireStore data does not show accessing hidden methods Lsun/misc/Unsafe;->putLong(Ljava/lang/Object; JJ)V (greylist, link, allow)
When I try to retrieve data from Firestore using the FirestoreRecyclerAdapter
, it doesn’t show up.
Error log
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 code
//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();
}
Model classes
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
Solution
When you attempt to map a document in Firestore to an object of type TestModel, the field names present in the class must match the property names present in the database. Unfortunately, in your case, the fields do not match. You see, the fields in the database are called “Story” and “Title”, while in the class they are called “mStory” and “mTitle”, which is not correct.
To solve this problem, you have two options, you can change the name of the property in the database to match the name in the class, or you can use a comment before the getter. For example, for the “mTitle” field, your getter should look like this:
@PropertyName("title")
public String getTitle() {
return mTitle;
}
In this way, you tell the compiler to look for a property named “title” instead of “mTitle”.