android Firebase应用程序创建用户,但在完成任务时显示失败

mwecs4sa  于 12个月前  发布在  Android
关注(0)|答案(1)|浏览(182)

我编程的应用程序中,用户注册,我也认为要求Firebase需要密码和电子邮件等。
当我通过创建一个帐户来测试注册时,firebase数据库创建了一个帐户,但在我的应用程序中,task.isSuccessful()方法返回false。
我也收到了这个“错误”/通知:
W/System:忽略标头X-Firebase-Locale,因为其值为null。
我已经检查了其他原因,如网络连接和错误与Firebase的要求,但它没有工作。
正如我在数据库中所说的,创建了一个帐户,但应用程序认为它没有。
我在Android Studio上用Java编程
下面是我的代码:

public void onClick(View view) {
        s_fName = fName.getEditText().getText().toString().trim();
        s_area = area.getEditText().getText().toString().trim();
        s_cpass = cpass.getEditText().getText().toString().trim();
        s_lName = lName.getEditText().getText().toString().trim();
        s_emailID = email.getEditText().getText().toString().trim();
        s_pass = pass.getEditText().getText().toString().trim();
        s_cpass = cpass.getEditText().getText().toString().trim();
        s_Stadtteil = stadtteil.getEditText().getText().toString().trim();
        s_house = house.getEditText().getText().toString().trim();
        s_mobile = mobileno.getEditText().getText().toString().trim();
        s_houseNo = houseno.getEditText().getText().toString().trim();

        if(isValid()) {
            System.out.println("Alles valid");
            //RelativeLayout layout = findViewById(this);

            final ProgressDialog mDialog = new ProgressDialog(ChefRegister.this);
            mDialog.setCancelable(false);
            mDialog.setCanceledOnTouchOutside(false);
            mDialog.setMessage("Registrierung wird abgeschlossen einen Moment bitte ...");
            mDialog.show();

            FirebaseAuth.getInstance().createUserWithEmailAndPassword(s_emailID, s_pass).addOnCompleteListener(new OnCompleteListener<AuthResult>() {
                @Override
                public void onComplete(@NonNull Task<AuthResult> task) {
                    if (task.isSuccessful()) {
                        String uid = FirebaseAuth.getInstance().getCurrentUser().getUid();
                        databaseReference = firebaseDatabase.getInstance().getReference("User").child(uid);
                        final HashMap<String, String> hashMap = new HashMap<>();
                        hashMap.put("Role", role);
                        databaseReference.setValue(hashMap).addOnCompleteListener(new OnCompleteListener<Void>() {
                            @Override
                            public void onComplete(@NonNull Task<Void> task) {
                                HashMap<String, String> hashMap1 = new HashMap<>();
                                hashMap1.put("Area", s_area);
                                hashMap1.put("First Name", s_fName);
                                hashMap1.put("Last Name", s_lName);
                                hashMap1.put("Email", s_emailID);
                                hashMap1.put("Stadtteil", s_Stadtteil);
                                hashMap1.put("Mobile No", s_mobile);
                                hashMap1.put("Password", s_pass);
                                hashMap1.put("Confirm Password", s_cpass);
                                hashMap1.put("Street", s_house);
                                hashMap1.put("house No", s_houseNo);

                                System.out.println("Checkpoint 1");
                                firebaseDatabase.getInstance().getReference("Chef").child(firebaseAuth.getInstance()
                                        .getCurrentUser().getUid()).setValue(hashMap1).addOnCompleteListener(new OnCompleteListener<Void>() {
                                    @Override
                                    public void onComplete(@NonNull Task<Void> task) {
                                        mDialog.dismiss();

                                        firebaseAuth.getCurrentUser().sendEmailVerification().addOnCompleteListener(new OnCompleteListener<Void>() {
                                            @Override
                                            public void onComplete(@NonNull Task<Void> task) {
                                                if(task.isSuccessful()){
                                                    System.out.println("Checkpoint 2");

                                                    AlertDialog.Builder builder = new AlertDialog.Builder(ChefRegister.this);
                                                    builder.setMessage("Registrierung erfolgreich abgeschlossen, bitte verifizieren Sie Ihre E-Mail");
                                                    builder.setCancelable(false);
                                                    builder.setPositiveButton("ok", new DialogInterface.OnClickListener() {
                                                        @Override
                                                        public void onClick(DialogInterface dialogInterface, int i) {
                                                            dialogInterface.dismiss();
                                                        }
                                                    });
                                                    builder.show();

                                                    AlertDialog Alert = builder.create();
                                                    Alert.show();
                                                }else{
                                                    mDialog.dismiss();
                                                    ReusableCodeForAll.ShowAlert(ChefRegister.this, "Error", task.getException().getMessage());
                                                }
                                            }
                                        });
                                    }
                                });
                                System.out.println("Checkpoint 3");
                            }
                        });
                    }
                    else{
                        mDialog.dismiss();
                        AlertDialog.Builder builder = new AlertDialog.Builder(ChefRegister.this);
                        builder.setMessage("Fehler bei der Registrierung stellen Sie sicher, dass Sie mit dem Internet verbunden sind");
                        builder.setCancelable(false);
                        builder.setPositiveButton("ok", new DialogInterface.OnClickListener() {
                            @Override
                            public void onClick(DialogInterface dialogInterface, int i) {
                                dialogInterface.dismiss();
                            }
                        });
                        builder.show();
                    }
                }
            });
        }
    }
});

字符串

9cbw7uwe

9cbw7uwe1#

如果Task失败,它包含一个异常,其中包含有关失败原因的信息。您应该记录该异常以找出错误所在:
于是:

FirebaseAuth.getInstance().createUserWithEmailAndPassword(s_emailID, s_pass).addOnCompleteListener(new OnCompleteListener<AuthResult>() {
    @Override
    public void onComplete(@NonNull Task<AuthResult> task) {
        if (task.isSuccessful()) {
            ...
        }
        else{
            Log.e("Auth", "Creating user failed", task.getException()); // 👈
            
            ...
        }
    }
})

字符串

相关问题