這是我嘗試使用唯一用戶 ID 更新數據的部分。但它總是顯示注冊失敗,即使身份驗證部分正在工作。mAuth.createUserWithEmailAndPassword(email,password) .addOnCompleteListener(new OnCompleteListener<AuthResult>() { @Override public void onComplete(@NonNull Task<AuthResult> task) { if (task.isSuccessful()) { user user=new user( nameOfUser, email, phNo ); //Toast.makeText(Register_User.this, "Working", Toast.LENGTH_SHORT).show(); mData.getReference("Users") .child(Objects.requireNonNull(FirebaseAuth.getInstance().getCurrentUser()).getUid()) .push().setValue(user).addOnCompleteListener(new OnCompleteListener<Void>() { @Override public void onComplete(@NonNull Task<Void> task) { progressBar.setVisibility(View.GONE); Toast.makeText(Register_User.this, "Upto here", Toast.LENGTH_LONG).show(); if (task.isSuccessful()) { Toast.makeText(Register_User.this, "Successfully Registered", Toast.LENGTH_SHORT).show(); } else { Toast.makeText(Register_User.this, "Failed to Registered", Toast.LENGTH_SHORT).show(); } } }); } else if (task.getException() instanceof FirebaseAuthUserCollisionException) { progressBar.setVisibility(View.GONE); Toast.makeText(getApplicationContext(), "You are already registered", Toast.LENGTH_SHORT).show(); } } });
1 回答

回首憶惘然
TA貢獻1847條經驗 獲得超11個贊
如果任務失敗,它會出現一個向您顯示問題的異常。您目前沒有以任何方式使用它,但它可能會為您指明解決方案:
if (task.isSuccessful()) {
Toast.makeText(Register_User.this, "Successfully Registered", Toast.LENGTH_SHORT).show();
} else {
Log.w(TAG, "Registering user failed", task.getException());
Toast.makeText(Register_User.this, "Failed to Registered", Toast.LENGTH_SHORT).show();
}
另請參閱Firebase 文檔中的創建基于密碼的帳戶。
添加回答
舉報
0/150
提交
取消