0


Im trying to make an app for android.
The app must have a login and register form and I can't understand why method onComplete doesn't work but data is added to the database in register page.
Here is the code :

private void submitForm(String email, String password){ auth.createUserWithEmailAndPassword(email, password) .addOnCompleteListener(RegisterActivity.this, new OnCompleteListener<AuthResult>() { @Override public void onComplete(@NonNull Task<AuthResult> task) { FirebaseAuthException e = (FirebaseAuthException)task.getException(); if(task.isSuccessful()){ Toast.makeText(RegisterActivity.this, "Registration successfully!", Toast.LENGTH_SHORT).show(); startActivity(new Intent(RegisterActivity.this, LoginActivity.class)); finish(); }else{ Toast.makeText(RegisterActivity.this, "" +e.getMessage(), Toast.LENGTH_SHORT).show(); } } }); } private void validate(String email, String password, String confirmPassword){ if(!TextUtils.isEmpty(email)) { if (android.util.Patterns.EMAIL_ADDRESS.matcher(email).matches()) { if ((!TextUtils.isEmpty(password)) && (!TextUtils.isEmpty(confirmPassword))) { if (!password.equals(confirmpassword)) { if(password.length() > 6){ submitForm(email, password); }else{ Toast.makeText(this, "Password must be at least 6 characters.", Toast.LENGTH_SHORT).show(); } } else { Toast.makeText(this, "Passwords do not match.", Toast.LENGTH_SHORT).show(); } } else { Toast.makeText(this, "Please fill in both password fields.", Toast.LENGTH_SHORT).show(); } }else{ Toast.makeText(this, "Please enter a valid email address.", Toast.LENGTH_SHORT).show(); } }else { Toast.makeText(this, "Please fill the email field.", Toast.LENGTH_SHORT).show(); } } @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_register); auth = FirebaseAuth.getInstance(); email = findViewById(R.id.emailEditText); password = findViewById(R.id.passwordEditText); confirmpassword = findViewById(R.id.confirmpasswordEditText); register = findViewById(R.id.registerbutton); register.setOnClickListener(new View.OnClickListener(){ @Override public void onClick(View view) { validate(email.getText().toString(), password.getText().toString(), confirmpassword.getText().toString()); } }); } 

When I add data to the database I expect to be trown on login page.

8
  • Is there any exception are you getting ? Commented May 21, 2018 at 7:30
  • finish() here is the problem Commented May 21, 2018 at 7:30
  • @JaiminModi yes: E/StorageHelpers: Failed to turn object into JSON java.lang.NullPointerException: Attempt to invoke virtual method 'org.json.JSONObject com.google.firebase.auth.internal.zzm.zzbf()' on a null object reference Commented May 21, 2018 at 7:35
  • @KopiBryant no, i already removed it and nothing happens :( Commented May 21, 2018 at 7:38
  • Which firebse version are you using? Commented May 21, 2018 at 7:39

1 Answer 1

1

While updating Firebase to latest version make sure you update your google play services also.

In my case with Firebase 15+ I had to set google play service (in project gradle)

classpath 'com.google.gms:google-services:3.3.1' 

Also try clear data & re-install app options.

Sign up to request clarification or add additional context in comments.

1 Comment

Please up-vote this answer, If helped. Happy Coding!