Java 在Firestore中找不到文档数据,返回null

Java 在Firestore中找不到文档数据,返回null,java,android,firebase,android-fragments,google-cloud-firestore,Java,Android,Firebase,Android Fragments,Google Cloud Firestore,我似乎无法将文本放入文本视图。数据来自Firestore数据库。当我运行它时,TextView为空并返回空值。下面是我到目前为止所做的。有人能看一下吗?你可以在这里看到我的数据库结构:[数据库结构图片][1] public class ProfileFragment extends Fragment { TextView firstNameText, age; private FirebaseAuth mAuth = FirebaseAuth.getInstance();

我似乎无法将文本放入文本视图。数据来自Firestore数据库。当我运行它时,TextView为空并返回空值。下面是我到目前为止所做的。有人能看一下吗?你可以在这里看到我的数据库结构:[数据库结构图片][1]

public class ProfileFragment extends Fragment {

    TextView firstNameText, age;
    private FirebaseAuth mAuth = FirebaseAuth.getInstance();
    private FirebaseFirestore db = FirebaseFirestore.getInstance();
    private FirebaseUser user = FirebaseAuth.getInstance().getCurrentUser();

    @Nullable
    @Override
    public View onCreateView(@NonNull LayoutInflater inflater, @Nullable ViewGroup container, @Nullable Bundle savedInstanceState) {

        View rootView = inflater.inflate(R.layout.fragment_profile, container, false);
        firstNameText = rootView.findViewById(R.id.profile_firstName);
        age = rootView.findViewById(R.id.profile_age);
        getUserInfo();

        return rootView;

    }

    public void getUserInfo() {
        db.collection("Users").document(mAuth.getCurrentUser().getEmail()).get().addOnCompleteListener(new OnCompleteListener<DocumentSnapshot>() {
            @Override
            public void onComplete(@NonNull Task<DocumentSnapshot> task) {
                if (task.isSuccessful()) {

                    DocumentSnapshot documentSnapshot = task.getResult();
                    String firstName = documentSnapshot.getString("Firstname");
                    Log.d(TAG, "Printing docData: " + documentSnapshot.getData());
                    firstNameText.setText(firstName);

                }
            }
        });
    }
}
公共类ProfileFragment扩展了片段{
text查看名字text,年龄;
私有FirebaseAuth mAuth=FirebaseAuth.getInstance();
私有FirebaseFirestore db=FirebaseFirestore.getInstance();
私有FirebaseUser用户=FirebaseAuth.getInstance().getCurrentUser();
@可空
@凌驾
创建视图时的公共视图(@NonNull LayoutInflater inflater、@Nullable ViewGroup container、@Nullable Bundle savedInstanceState){
视图根视图=充气机。充气(R.layout.fragment_外形,容器,假);
firstNameText=rootView.findviewbyd(R.id.profile\u firstName);
年龄=rootView.findviewbyd(R.id.profile\u年龄);
getUserInfo();
返回rootView;
}
public void getUserInfo(){
db.collection(“Users”).document(mAuth.getCurrentUser().getEmail()).get().addOnCompleteListener(新的OnCompleteListener()){
@凌驾
未完成的公共void(@NonNull任务){
if(task.issusccessful()){
DocumentSnapshot DocumentSnapshot=task.getResult();
String firstName=documentSnapshot.getString(“firstName”);
Log.d(标记“打印docData:+documentSnapshot.getData());
firstNameText.setText(firstName);
}
}
});
}
}
我猜

mAuth.getCurrentUser().getEmail()
问题出在这里。请尝试将用户的电子邮件放入字符串中

mAuth = FirebaseAuth.getInstance();
     final FirebaseUser theUser = mAuth.getCurrentUser();
     if (theUser !=null)
     String UID = theUser.getEmail().toString();
替换

 mAuth.getCurrentUser().getEmail()

使用UID。

请将您的数据库结构添加为JSON文件或至少一个屏幕截图。@AlexMamo谢谢,我已经添加了图片。您的代码是否包含在成功响应中?还是失败?日志显示了什么?响应的NIDE任务对象是什么?当使用这行代码
Log.d(标记“Printing docData:”+documentSnapshot.getData())时,它是否在logcat中打印出来?请同时回复@Alexmamo您是否可以共享日志?以及文档快照的内容