Quelle est la cause profonde de ce problème/erreur ? Comment le résoudre ? Mon modèle de données n'est-il pas correctement structuré ? Ou est-ce que je fais une mauvaise requête ?
// Ajout d'un nouveau commentaire
String comment = medit.getText().toString();
Comment newComment = new Comment(user,comment,postKey);
db.child("Post-Comments").child(postKey).push().setValue(newComment);
// Récupération de tous les commentaires d'un message //utilisation de FirebaseRecyclerView et fragment
DatabaseReference mRef = db.child("Post-Comments").child(postKey).getRef();
adapter = new FirebaseRecyclerAdapter<Comment, myViewHolder> (Comment.class,
R.layout.comment_list_layout,myViewHolder.class, mRef)
{
@Override
protected void populateViewHolder(myViewHolder viewHolder,
Comment model, int position) {
viewHolder.bindToComments(model);
}
};
rlm2 = new LinearLayoutManager(getActivity());
rv2.setLayoutManager(rlm2);
rv2.setAdapter(adapter);
// Classe de commentaires
public class Comment {
public String comment;
public String reactUserId;
public Map<String,String> created_on;
public String postKey;
public Comment() {
}
public Comment(String reactUserId, String comment, String postKey) {
this.reactUserId = reactUserId;
this.postKey = postKey;
this.comment = comment;
this.created_on = ServerValue.TIMESTAMP;
}
public Map<String,Object> toMap(){
Map<String,Object> values = new HashMap<>();
values.put("userId",reactUserId);
values.put("postKey",postKey);
values.put("comment",comment);
values.put("created_on",created_on);
return values;
}
}// more getter and setters
// Stacktrace
10745-10745/com.dhiraj.firebaseapp E/AndroidRuntime: FATAL EXCEPTION: main
com.google.firebase.database.DatabaseException:
Expected a Map while deserializing, but got a class java.lang.Long
//JSON de la base de données Firebase
{
"Post-Comments" : {
"-KPE1qy6FgcwOnb1YXRw" :
"-KPE1zMFviLJvEKxexB7" : {
"AUTHOR" : "Dheeraj",
"comment" : "the first time I am not sure if you have any questions please ",
"created_on" : 1471278741281,
"postKey" : "-KPE1qy6FgcwOnb1YXRw",
"reactUserId" : "Dheeraj"
},
"-KPE221Xk5t9aMJfYoKD" : {
"AUTHOR" : "Dheeraj",
"comment" : "the first time I am not sure if you have any questions please ",
"created_on" : 1471278756332,
"postKey" : "-KPE1qy6FgcwOnb1YXRw",
"reactUserId" : "Dheeraj"
}
}
},
"Posts" : {
"-KPE1qy6FgcwOnb1YXRw" : {
"created on" : 1471278706910,
"desc" : "the only one who has been sent to you and your family and friends are invited to view the full image to open ",
"title" : "the following link ",
"userId" : "Dhiraj"
},
"-KPE1vlYc5vF7AyL2OHL" : {
"created on" : 1471278726738,
"desc" : "hi I was thinking that it will take place at all and all the best way is to have ",
"title" : "good afternoon ",
"userId" : "Dhiraj"
}
},
}