FireStore Data Not Showing Accessing hidden method Lsun/misc/Unsafe;->putLong(Ljava/lang/Object;JJ)V (greylist, linking, allowed)

Viewed 1852

When I try to retrieve data from Firestore using FirestoreRecyclerAdapter it's not showing.

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();
}

ModelClass

 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

1 Answers

When you try to map a document from Firestore into an object of type "TestModel", the name of the fields that exist in your class must match the name of your properties that exist in your database. Unfortunately, in your case, the fields don't match. See, the fields in your database are called "story" and "title", while in the class are called "mStory" and "mTitle", and this is not correct.

To solve this, you have two options, you either change the name of your properties in the database to match the one in the class, or you can use an annotation in front of the getters. 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 called "title" and not "mTitle".

Related