gpt4 book ai didi

android - "task.isSuccessful"在CreatewithUseremailandpassword 中总是返回false

转载 作者:行者123 更新时间:2023-11-30 05:10:33 26 4
gpt4 key购买 nike

我已使用 createUserWithEmailAndPassword 方法注册用户,他们已在我的 firebase 项目中注册(我可以看到他们的信息)。但是,当我尝试使用创建的电子邮件和密码登录时,task.isSuccessful 方法始终返回 false,并且每次都运行 else 语句。

登录注册码:

private Button buttonRegister;
private EditText editTextEmail;
private EditText editTextPassword;
private TextView textViewSignin;

private ProgressDialog progressDialog;
private FirebaseAuth firebaseAuth;

@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
progressDialog=new ProgressDialog(this);
firebaseAuth= FirebaseAuth.getInstance();


buttonRegister = (Button) findViewById(R.id.buttonRegister);

editTextEmail=(EditText) findViewById(R.id.editTextEmail);
editTextPassword=(EditText) findViewById(R.id.editTextPassword);

textViewSignin=(TextView) findViewById(R.id.textViewSignin);

buttonRegister.setOnClickListener(this);
textViewSignin.setOnClickListener(this);

if(firebaseAuth.getCurrentUser()!=null){
//start the profile activity
finish();
startActivity(new Intent(getApplicationContext(), ProfileActivity.class));
}


}

private void registerUser(){
String email=editTextEmail.getText().toString().trim();
String password=editTextEmail.getText().toString().trim();

if(TextUtils.isEmpty(email)){
Toast.makeText(this, "Please enter E-mail first", Toast.LENGTH_SHORT).show();
return;
}

if(TextUtils.isEmpty(password)){
Toast.makeText(this, "Please enter password first", Toast.LENGTH_SHORT).show();
return;
}

progressDialog.setMessage("Registerring User......");
progressDialog.show();


firebaseAuth.createUserWithEmailAndPassword(email, password)
.addOnCompleteListener(this, new OnCompleteListener<AuthResult>() {
@Override
public void onComplete(@NonNull Task<AuthResult> task) {
progressDialog.dismiss();
if(task.isSuccessful()){
finish();
startActivity(new Intent(getApplicationContext(), ProfileActivity.class));
}
else{
Toast.makeText(MainActivity.this, "Unable to Register! Please try again.", Toast.LENGTH_SHORT).show();
}
}
});


}

@Override
public void onClick(View v) {
if(v == buttonRegister){
registerUser();
}

if(v == textViewSignin){
finish();
startActivity(new Intent(this, LoginActivity.class));
}

}

最佳答案

@赫曼特亚达夫

您是否检查过 firebase 在返回 false 时给出的异常?请使用以下代码检查当时发生了什么异常:

task.getException() //which returns the exception that caused the Task to fail.

检查并更新您遇到的异常,以便我们可以帮助您,或者您可以提出解决问题的想法?

关于android - "task.isSuccessful"在CreatewithUseremailandpassword 中总是返回false,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/53826745/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com