首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >代码跳转到注册app中创建账号的错误语句坚持

代码跳转到注册app中创建账号的错误语句坚持
EN

Stack Overflow用户
提问于 2019-08-23 19:00:15
回答 1查看 34关注 0票数 0

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

代码语言:javascript
复制
   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);
}
}
EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2019-08-23 19:11:37

替换这个

代码语言:javascript
复制
if (rpassword == password ){

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

    }

有了这个

代码语言:javascript
复制
 if (rpassword.equals(password) ){

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

    }
票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/57624979

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档