当我尝试单击创建帐户按钮时,应用程序不断崩溃

时间:2019-05-22 04:49:54

标签: android firebase-authentication

我正在尝试创建登录并使用Firebase在android studio上进行注册,但是每次我单击该按钮转到我的注册页面时,该应用都会崩溃。登录屏幕可以正常运行。以下是我的注册页面的代码。

public class signup extends AppCompatActivity {

    private Button accountSignUp;
    private EditText createEmail;
    private EditText createPassword;


    private static final String TAG = "";


    private FirebaseAuth mAuth;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_signup);

        createEmail = (EditText) findViewById(R.id.txtCreateE);
        createPassword = (EditText) findViewById(R.id.txtCreateP);
        accountSignUp = (Button) findViewById(R.id.btnAccountSignUp);

        mAuth = FirebaseAuth.getInstance();


        accountSignUp.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {

                String email = createEmail.getText().toString();
                String password = createPassword.getText().toString();

                if (TextUtils.isEmpty(email)) {
                    Toast.makeText(getApplicationContext(),
                            "Enter Email", Toast.LENGTH_SHORT).show();
                    return;
                }
                if (TextUtils.isEmpty(password)) {
                    Toast.makeText(getApplicationContext(),
                            "Enter Password", Toast.LENGTH_SHORT).show();
                    return;
                }

                mAuth.createUserWithEmailAndPassword(email, password)
                        .addOnCompleteListener(signup.this,
                        new OnCompleteListener<AuthResult>() {
                    @Override
                    public void onComplete(@NonNull Task<AuthResult> task) {

                        if (task.isSuccessful()){

                            Log.d(TAG, "createUserWithEmail:success");
                            FirebaseUser user = mAuth.getCurrentUser();
                            Intent intent = new Intent(signup.this, HomeScreen.class);
                            startActivity(intent);
                            finish();

                        }else{

                            Log.w(TAG, "createUserWithEmail:failure", task.getException());
                            Toast.makeText(signup.this, "Failed", Toast.LENGTH_SHORT).show();

                        }


                    }
                });

            }
        });


    }//end of onCreate
}

0 个答案:

没有答案