0

i was trying to make register login using google firebase, but when running the project the project was crash,but when in the logo screen or splash screen the project fine, but when next activity the project crash suddenly

and when i type new View.OnClickListener() word grey color like useless code can any one help me?

this is my code

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

    mName = findViewById(R.id.RegisterName);
    mEmail = findViewById(R.id.RegisterEmail);
    mPassword = findViewById(R.id.RegisterPassword);
    mLoginBtn = findViewById(R.id.txtLogin);

    fAuth = FirebaseAuth.getInstance();
    progressBar = findViewById(R.id.progressBar);

    if(fAuth.getCurrentUser() !=null){
        startActivity(new Intent(getApplicationContext(), menuAwal.class)) ;
        finish();
    }

    mRegisterBtn.setOnClickListener(new View.OnClickListener(){
        public void onClick(View V){
            String email = mEmail.getText().toString().trim();
            String password = mPassword.getText().toString().trim();

            if(TextUtils.isEmpty(email)) {
                mEmail.setError("Email is Required.");
                return;
            }
            if(TextUtils.isEmpty(password)){
                mPassword.setError("Password is Required");
                return;
            }

            if(password.length() < 6){
                mPassword.setError("Password must be >=6 Characers");
                return;
            }

            progressBar.setVisibility(View.VISIBLE);


                    //register user to firebase

                    fAuth.createUserWithEmailAndPassword(email,password).addOnCompleteListener(new OnCompleteListener<AuthResult>() {
                        @Override
                        public void onComplete(@NonNull Task<AuthResult> task) {
                            if(task.isSuccessful()){
                                Toast.makeText(registerActivity.this, "User created", Toast.LENGTH_SHORT).show();
                                startActivity(new Intent(getApplicationContext(),menuAwal.class));
                            }else{
                                Toast.makeText(registerActivity.this, "Error!" + task.getException().getMessage(), Toast.LENGTH_SHORT).show();
                            }
                        }
                    });
                }
            });
        }
    }
Trandafir
  • 11
  • 1
  • 1
    If the app crashes, there is a stack trace. Please look that up on logcat, and add it to your question. Please respond with @AlexMamo – Alex Mamo Nov 11 '21 at 07:56
  • most likely `mRegisterBtn` is null, but more importantly, learn how to find and use stack traces – a_local_nobody Nov 11 '21 at 07:57

0 Answers0