I am trying to take the value of the description field and I am doing it inside an onBindViewHolder of a Recyclerview adapter to show ipost of the followed users:
This is what I'm trying to do to get the description in the pre-shown structure:
FirebaseFirestore.getInstance().document("/post").collection(listUserId).document("userPosts").get().addOnSuccessListener(new OnSuccessListener<DocumentSnapshot>() {
@Override
public void onSuccess(DocumentSnapshot documentSnapshot) {
findFriendsViewHolder.txtDescrizione.setText(documentSnapshot.getString("description"));
}
});
But when I try to run the app (only if the lines of code I just showed are present) the app crashes and the following error is shown in the logcats:
Process: com.conta.pophome, PID: 9348 java.lang.IllegalArgumentException: Invalid document reference. Document references must have an even number of segments, but post has 1
[... etc] at com.conta.pophome.MainActivity$5.onBindViewHolder(MainActivity.java:236) at com.conta.pophome.MainActivity$5.onBindViewHolder(MainActivity.java:229) [... etc]
Is there anyone who could help me resolve this error? I leave you the complete code:
FirestoreRecyclerOptions<GetInfoPost> options
= new FirestoreRecyclerOptions.Builder<GetInfoPost>()
.setQuery(FirebaseFirestore.getInstance().collection("following").document(fAuth.getCurrentUser().getUid()).collection("/userFollowing").limit(1000), GetInfoPost.class)
.build();
FirestoreRecyclerAdapter<GetInfoPost, FindFriendsViewHolder> firestoreRecyclerAdapter
=new FirestoreRecyclerAdapter<GetInfoPost, FindFriendsViewHolder>(options) {
@Override
protected void onBindViewHolder(@NonNull FindFriendsViewHolder findFriendsViewHolder, int i, @NonNull GetInfoPost getInfoPost) {
final String listUserId = getSnapshots().getSnapshot(i).getId();
FirebaseFirestore.getInstance().document("/post").collection(listUserId).document("userPosts").get().addOnSuccessListener(new OnSuccessListener<DocumentSnapshot>() {
@Override
public void onSuccess(DocumentSnapshot documentSnapshot) {
findFriendsViewHolder.txtDescrizione.setText(documentSnapshot.getString("description"));
}
});
}
@NonNull
@Override
public FindFriendsViewHolder onCreateViewHolder(@NonNull ViewGroup parent, int viewType) {
View view = LayoutInflater.from(parent.getContext()).inflate(R.layout.post,parent,false);
FindFriendsViewHolder viewHolder = new FindFriendsViewHolder(view);
return viewHolder;
}
};
findPost.setAdapter(firestoreRecyclerAdapter);
firestoreRecyclerAdapter.startListening();