My Problem
08-10 04:23:28.820 21501-21501/my.org.medicare.medicareapp E/AndroidRuntime: FATAL EXCEPTION: main
Most likely this is your problem, in your fetchData
method:
private void fetchData(DataSnapshot dataSnapshot)
{
spacecrafts.clear();
//dataSnapshot.getChildren()
for (DataSnapshot ds : dataSnapshot.getChildren()) //--> At this point, ds is an iterator of dataSnapshot; it will iterate the dataSnapshot's children. In this case, the first child's type is String, thus the first iteration of ds will have a type of String.
{
System.out.println(ds.getValue());
protest spacecraft=ds.getValue(protest.class); //--> at this point, you tried to assign a String to an Object with type "protest" by conversion. This is illegal, so it will throw an exception instead.
spacecrafts.add(spacecraft);
}
}
I hope this helps.
Your fetchData
function already receives DataSnapshot
as a child-node, but even here you still loop through the children which will effectively be looping through individual keys (name
, contact
, centre
).
You should simply call getValue
on DataSnaphot
without looping:
private void fetchData(DataSnapshot dataSnapshot)
{
spacecrafts.clear();
protest spacecraft=dataSnapshot.getValue(protest.class);
spacecrafts.add(spacecraft);
}
I hope this helps.