DatabaseException: Can't convert object of type java.lang.String to type Models.OrderDetails

前端 未结 1 1601
你的背包
你的背包 2021-01-27 06:31

This is my database structure. I am trying to fetch Order Details.

Here is the code

 databaseReference = FirebaseDatabase.getI         


        
相关标签:
1条回答
  • 2021-01-27 06:55

    The problem is you are trying to convert a string ( the values in OrderDetails) to OrderDetails object

    Solution:

    databaseReference = FirebaseDatabase.getInstance().getReference().child("Admin Order").
                child(userID);
        databaseReference.addValueEventListener(new ValueEventListener() {
            @Override
            public void onDataChange(@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 = new PreviousOrderAdapter(getContext(), mList);
                recyclerView.setAdapter(adapter);
            }
    
            @Override
            public void onCancelled(@NonNull DatabaseError databaseError) {
                progressBar.setVisibility(View.INVISIBLE);
            }
        });
    
    0 讨论(0)
提交回复
热议问题