When i try to get a Object from addChildListerner(DataSnapShot) it works fine and assign to DataSnapshot to object
This working fine:
myRef = database.getReference("Chat").child(Combine);
myRef.orderByKey().limitToLast(1).addChildEventListener(new ChildEventListener() {
@Override
public void onChildAdded(@NonNull DataSnapshot dataSnapshot, @Nullable String s) {
ChatData user = dataSnapshot.getValue(ChatData.class);
userChild.add(user);
But when i try to get same Object using ValueListerner(snapshot) app crash
i have use everything snapshot.getChildern ()
snapshot.getValue
then app crash.
Error With
myRef = database.getReference("Chat").child(Combine);
myRef.orderByKey().limitToLast(1).addListenerForSingleValueEvent(new ValueEventListener() {
@Override
public void onDataChange(@NonNull DataSnapshot dataSnapshot) {
ChatData user = dataSnapshot.getValue(ChatData.class);
userChild.add(user);
}
i want to retrieve ChatData user = dataSnapshot.getValue(ChatData.class); userChild.add(user);
Debug time :
DataSnapshot { key =
1123469ACDEFFFFGJKLNOOOPQSTUUVWZabccdehhkkloopqruuuuwxyy,
value
= {-LrjsM3ZO0pzQbvCcRuQ
={time=Tue Oct 22 00:53:10 GMT+05:00 2019
, msg=hi
, user_ID=LuFro93OCcPEpoFTKuQhUkeuw462}}
}
How to get this Value