代码跳转到错误语句坚持在注册应用程序中创建帐户



当我编译它时,我正在尝试在我的 android 应用程序中创建一个注册活动,并且错误当我运行我的应用程序时似乎存在逻辑问题 创建新帐户的瞬间,它会跳转到错误代码,因为我在 if 语句中的 in 方法 creatnewAccount(( 中提供了我的注册活动代码,我试图检查 rpassword 和密码是否为相同。每当我运行我的应用程序并输入详细信息并单击注册按钮时,它都会跳转到 else 语句。不明白错误是什么,我该怎么办

package com.nanb.chaton;
import androidx.annotation.NonNull;
import androidx.appcompat.app.AppCompatActivity;
import android.app.ProgressDialog;
import android.content.Intent;
import android.os.Bundle;
import android.text.TextUtils;
import android.view.View;
import android.widget.Button;
import android.widget.EditText;
import android.widget.Toast;
import com.google.android.gms.tasks.OnCompleteListener;
import com.google.android.gms.tasks.Task;
import com.google.firebase.auth.AuthResult;
import com.google.firebase.auth.FirebaseAuth;
import static android.widget.Toast.LENGTH_SHORT;
public class Register extends AppCompatActivity {
private EditText Email, Password, Repassword;
private Button Signup, Login;
private FirebaseAuth mAuth;
private ProgressDialog lodingBar;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_register);
mAuth = FirebaseAuth.getInstance();
rimplemantaion();
sendusertoLogin();
createAccount();
}
private void createAccount() {
Signup.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
createnewAccount();
}
});
}
private void createnewAccount() {
String email = Email.getText().toString();
String password = Password.getText().toString();
String rpassword = Repassword.getText().toString();
if (TextUtils.isEmpty(email)){
Toast.makeText(this, "Please enter email i'd ", LENGTH_SHORT).show();
}
if (TextUtils.isEmpty(password)){
Toast.makeText(this, "Please enter Password ", LENGTH_SHORT).show();
}
if (TextUtils.isEmpty(rpassword)){
Toast.makeText(this, "Please enter Re-Password ", LENGTH_SHORT).show();
}
if (rpassword == password ){
lodingBar.setTitle("Creating new account");
lodingBar.setMessage("Pleased wait till we creat your account");
lodingBar.setCanceledOnTouchOutside(true);
lodingBar.show();
mAuth.createUserWithEmailAndPassword(email, password).addOnCompleteListener(new OnCompleteListener<AuthResult>() {
@Override
public void onComplete(@NonNull Task<AuthResult> task) {
if (task.isSuccessful()) {
sendusertoLogin();
Toast.makeText(Register.this,"Account created succcessfully", Toast.LENGTH_SHORT).show();
lodingBar.dismiss();
}else{
Toast.makeText(Register.this,"Sorry,There is a problem while creating your accout. Please try again later", LENGTH_SHORT).show();
lodingBar.dismiss();
}
}
});
}
else{
Toast.makeText(this, "Password and Re-enter password are not same ", LENGTH_SHORT).show();
}
}
private void sendusertoLogin() {
Login.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
Intent loginIntent = new Intent(Register.this, Login.class);
startActivity(loginIntent);
}
});
}
private void rimplemantaion() {
Email = (EditText) findViewById(R.id.email);
Password = (EditText) findViewById(R.id.password);
Repassword = (EditText) findViewById(R.id.Rpassword);
Signup = (Button) findViewById(R.id.SignUp);
Login = (Button) findViewById(R.id.LogIn);
lodingBar = new ProgressDialog(this);
}
}

替换这个

if (rpassword == password ){
}
else{
Toast.makeText(this, "Password and Re-enter password are not same ", LENGTH_SHORT).show();
}

有了这个

if (rpassword.equals(password) ){
}
else{
Toast.makeText(this, "Password and Re-enter password are not same ", LENGTH_SHORT).show();
}

最新更新