使用Firebase在Android中检索数据

时间:2017-03-23 15:54:11

标签: android firebase firebase-realtime-database

我是Firebase的新手,我正在尝试从云端获取数据到我的项目

DatabaseReference userRef = ref.child(user.getUid());

    userRef.addValueEventListener(new ValueEventListener() {
        @Override
        public void onDataChange(DataSnapshot dataSnapshot) {
            UserDoctor userDoctor = dataSnapshot.getValue(UserDoctor.class);
            tempName = userDoctor.getName();
        }

        @Override
        public void onCancelled(DatabaseError databaseError) {

        }
    });

但问题是我无法将字符串分配给tempName,它返回“null”

this link

UserDoctor类就在这里

public class UserDoctor {
public String address;
public String major;
public String mobile;
public String name;
public String workplace;

public UserDoctor(){}

public UserDoctor(String _address, String _major, String _mobile, String _name, String _workplace){
    name = _name;
    address = _address;
    major = _major;
    mobile = _mobile;
    workplace = _workplace;
}

public String getName() {
    return name;
}

}

非常感谢!

0 个答案:

没有答案