Databaseexception: Can't Convert Object Of Type Java.lang.string To Type Models.orderdetails
This is my database structure. I am trying to fetch Order Details. Here is the code databaseReference = FirebaseDatabase.getInstance().getReference().child('Admin Order').
Solution 1:
The problem is you are trying to convert a string ( the values in OrderDetails
) to OrderDetails
object
Answer :
databaseReference = FirebaseDatabase.getInstance().getReference().child("Admin Order").
child(userID);
databaseReference.addValueEventListener(newValueEventListener() {
@OverridepublicvoidonDataChange(@NonNull DataSnapshot dataSnapshot) {
for (DataSnapshot childSnapshot : dataSnapshot.getChildren()) {
OrderDetails orderDetails = childSnapshot.child("Order Details").getValue(OrderDetails.class);
Log.w("orderDetails", orderDetails.getConsumer());
mList.add(details);
progressBar.setVisibility(View.INVISIBLE);
}
adapter = newPreviousOrderAdapter(getContext(), mList);
recyclerView.setAdapter(adapter);
}
@OverridepublicvoidonCancelled(@NonNull DatabaseError databaseError) {
progressBar.setVisibility(View.INVISIBLE);
}
});
Post a Comment for "Databaseexception: Can't Convert Object Of Type Java.lang.string To Type Models.orderdetails"