Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/java/321.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Java Firebase云Firestore引用返回null_Java_Android_Firebase_Google Cloud Firestore - Fatal编程技术网

Java Firebase云Firestore引用返回null

Java Firebase云Firestore引用返回null,java,android,firebase,google-cloud-firestore,Java,Android,Firebase,Google Cloud Firestore,所以,我在firestore中创建了firebase用户配置文件,它将保存用户的数据,例如他们的姓名、电子邮件、电话号码和奖励积分。用户使用Google登录登录 这就是我将数据写入firestore的方式 private void addNewUser() { FirebaseUser user = FirebaseAuth.getInstance().getCurrentUser(); if (user != null) { String uid = user

所以,我在firestore中创建了firebase用户配置文件,它将保存用户的数据,例如他们的姓名、电子邮件、电话号码和奖励积分。用户使用Google登录登录

这就是我将数据写入firestore的方式

 private void addNewUser() {
    FirebaseUser user = FirebaseAuth.getInstance().getCurrentUser();
    if (user != null) {
        String uid = user.getUid();
        for (UserInfo profile : user.getProviderData()) {
            // Id of the provider (ex: google.com)
            String providerId = profile.getProviderId();

            // UID specific to the provider

            // Name, email address, and profile photo Url
            String name = profile.getDisplayName();
            String email = profile.getEmail();


            Map<String, Object> newUser = new HashMap<>();
            newUser.put("Nama", name);
            newUser.put("Email", email);




            // Add a new document with a generated ID
            db.collection("users").document(uid).set(newUser);
                        }


        }


    }

在本例中,文档引用
curUser
,返回null。我不知道我做错了什么

您需要在
文档参考

    @Override
public void onStart() {
    super.onStart();
    // Check if user is signed in (non-null) and update UI accordingly.
    FirebaseUser user = FirebaseAuth.getInstance().getCurrentUser();
    if (user != null) {
        String curUser = user.getUid();
        DocumentReference documentReference = db.document(curUser);
        documentReference.addSnapshotListener(this.getActivity(), new EventListener<DocumentSnapshot>() {
            @Override
            public void onEvent(@javax.annotation.Nullable DocumentSnapshot documentSnapshot, @javax.annotation.Nullable FirebaseFirestoreException e) {
                if (documentSnapshot.exists()) {
                    String userNama = documentSnapshot.getString(KEY_NAMA);
                    String userEmail = documentSnapshot.getString(KEY_EMAIL);

                    namaUser.setText(userNama);
                    emailUser.setText(userEmail);
                }
            }
        });




    } else {

        Intent intent = new Intent(Home.this.getActivity(), LoginActivity.class);
        startActivity(intent);


        }

    }
变,

DocumentReference documentReference = db.document(curUser);
对,

DocumentReference documentReference = db.collection("users").document(curUser);