Firebase onDataChange或onCancelled均未被调用

时间:2019-12-17 18:03:51

标签: java android firebase firebase-realtime-database

我在数据库中有这样的用户:

users database

我尝试使用帮助程序类来读取用户 还有这种方法

public void readUser (final FirebaseUserHelper.DataStatusUser dataStatus)
{
    mReference.addValueEventListener(new ValueEventListener() {
        @Override
        public void onDataChange(@NonNull DataSnapshot dataSnapshot) {
            user = (User) dataSnapshot.getValue(User.class);

            dataStatus.DataIsLoaded(user,userKey);
        }

        @Override
        public void onCancelled(@NonNull DatabaseError databaseError) {
            Log.e("User", databaseError.getMessage() );

        }
    });

当我调试时,我看到引用是好的,但是被调用了onDataChangeonCancelled方法。

public class FirebaseUserHelper {
    private FirebaseDatabase mDatabase;
    private DatabaseReference mReference;
    private String userKey;
    private  User user;
    public interface DataStatusUser
    {
        void DataIsLoaded( User user, String key);

    }

    public FirebaseUserHelper()
    {
        FirebaseAuth firebaseAuth = FirebaseAuth.getInstance();
        mDatabase = FirebaseDatabase.getInstance();
        userKey = firebaseAuth.getCurrentUser().getUid();
        mReference=mDatabase.getReference("Users").child(userKey);
    }
}

0 个答案:

没有答案