this is the error am getting
com.google.firebase.database.DatabaseException: Can’t convert object of type java.lang.Boolean to type com.stys.kneckenyapastpapers.model.course_followers
here’s the code
mDatabase = FirebaseDatabase.getInstance().getReference("Followers").child("Course").child("AGRI");
mDatabase.addListenerForSingleValueEvent(new ValueEventListener() {
@SuppressLint("NotifyDataSetChanged")
@Override
public void onDataChange(@NonNull DataSnapshot snapshot) {
for (DataSnapshot di : snapshot.getChildren()) {
course_followers course_followers = di.getValue(course_followers.class);
follower.add(course_followers);
if (dataSnapshot.child(user.getId()).exists()) {
mUSer.add(user);
}
}
}
Toast.makeText(getContext(), String.valueOf(follower.size()), Toast.LENGTH_SHORT).show();
}
@Override
public void onCancelled(@NonNull DatabaseError error) {
}
});
2
Answers
This line is culprit
You should try this instead
There is no need to create any class when only want to read only some keys in the Realtime Database. Classes are required only when you want to map a node into an object of a particular class. This means that the fields inside the class should be exactly the same as the ones in the database. So it’s not your case because those UIDs are dynamically added. To read those keys, please use the following lines of code: