I have the following code trying to retrieve firebase values. My database structure is as follows:
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_mystatement);
listview = (ListView) findViewById(R.id.listview);
adapter = new ArrayAdapter<String>(this, android.R.layout.simple_dropdown_item_1line, list);
listview.setAdapter(adapter);
dref = FirebaseDatabase.getInstance().getReference();
dref = dref.child("Dog Expenditure");
dref.addValueEventListener(new ValueEventListener() {
@Override
public void onDataChange(DataSnapshot dataSnapshot) {
for (DataSnapshot child : dataSnapshot.getChildren()) {
HashMap<String, Object> value = (HashMap<String, Object>) child.getValue();
String amount = value.get("amount").toString();
String item = value.get("item").toString();
// This will print out amount and item
System.out.println(amount + item);
}
}
@Override
public void onCancelled(DatabaseError databaseError) {
}
});
}
I have tried different ways to do this but i do not just get any luck here..All i get is this error java.lang.ClassCastException: java.lang.String cannot be cast to java.util.HashMap at com.example.moses.farm.Mystatement$1.onDataChange(Mystatement.java:39) which points to this HashMap value = (HashMap) child.getValue(); line of code. I have been stuck here for almost a week, anyone with an idea of how to get this will truly help me

Stringplease check it...Map<String, Object> value = (Map<String, Object>) child.getValue()