无法拒绝
final FirebaseUser firebaseUser = FirebaseAuth.getInstance();
如果我将其更改为
final FirebaseAuth firebaseAuth = FirebaseAuth.getInstance();
它不会解析其中的getUid
if (!user.getUser_id().equals(firebaseUser.getUid())){
mUsers.add(user);
如果我将其更改为FirebaseUser firebaseUser = FirebaseUser.getInstance();
,它将无法解析getInstance();我该如何删除错误,请帮忙
private void readUsers() {
final FirebaseUser firebaseUser = FirebaseAuth.getInstance();
DatabaseReference reference = FirebaseDatabase.getInstance().getReference("users");
reference.addValueEventListener(new ValueEventListener() {
@Override
public void onDataChange(DataSnapshot dataSnapshot) {
mUsers.clear();
for (DataSnapshot snapshot : dataSnapshot.getChildren()){
User user = snapshot.getValue(User.class);
assert user !=null;
assert firebaseUser !=null;
if (!user.getUser_id().equals(firebaseUser.getUid())){
mUsers.add(user);
}
}
userAdapter = new UserAdapter(getContext(), mUsers);
recyclerView.setAdapter(userAdapter);
}
@Override
public void onCancelled(DatabaseError databaseError) {
}
});
}
答案 0 :(得分:1)
FirebaseAuth.getInstance()
返回FirebaseAuth
的实例,因此:
final FirebaseUser firebaseUser = FirebaseAuth.getInstance();
应改为:
final FirebaseAuth auth = FirebaseAuth.getInstance();
然后更改此:
assert user !=null;
assert firebaseUser !=null;
if (!user.getUser_id().equals(firebaseUser.getUid())){
mUsers.add(user);
}
对此:
if (!user.getUser_id().equals(auth.getCurrentUser().getUid())){
mUsers.add(user);
}