I have tried since last 2 hours to solve this exception..I got the line of code throwing exception.. but didn't find solution..Please help me error occurs @ mUsers.add(user); //in else part
private void readChats()
{
mUsers = new ArrayList<>();
databaseReference = FirebaseDatabase.getInstance().getReference("Users");
databaseReference.addValueEventListener(new ValueEventListener()
{
@Override
public void onDataChange(@NonNull DataSnapshot dataSnapshot) {
try {
mUsers.clear();
for (DataSnapshot snapshot : dataSnapshot.getChildren()) {
User user = snapshot.getValue(User.class);
//displaying 1 user from chat
for (String id : usersList) {
if (user.getUserId().equals(id)) {
if (mUsers.size() != 0) {
for (User user1 : mUsers) {
if (!user.getUserId().equals(user1.getUserId())) {
mUsers.add(user);
}
}
} else {
mUsers.add(user);
}
}
}
}//end of for
userAdapter = new UserAdapter(getContext(), mUsers);
recyclerView.setAdapter(userAdapter);
}
catch (Exception e)
{
Toast.makeText(getContext(), e.toString(), Toast.LENGTH_SHORT).show();
}
}
@Override
public void onCancelled(@NonNull DatabaseError databaseError) {
}
});
}//end of readChats
//this is the method