0

im getting this error and im absolutly frustrated. Im trying to connect my app with my firebase realtime databse to make a log in system but its just dont working. Im really strugggeling at this and it could be nice if someone could help me. I also have an error where it says: "Please change your database URL to ..." and i dont know what that does exactly mean.

public class RegisterUser extends AppCompatActivity implements View.OnClickListener {

private FirebaseAuth mAuth;

private TextView banner, registerUser;
private EditText editTextPersonName,editTextTextPersonName2,editTextEmail,editTextPassword;

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

    mAuth = FirebaseAuth.getInstance();

    banner = (TextView) findViewById(R.id.banner);
    banner.setOnClickListener(this);

    registerUser = (Button) findViewById(R.id.register);
    registerUser.setOnClickListener(this);

    editTextPersonName = (EditText) findViewById(R.id.fullname);
    editTextTextPersonName2 = (EditText) findViewById(R.id.username);
    editTextEmail = (EditText) findViewById(R.id.email);
    editTextPassword = (EditText) findViewById(R.id.password);
}

public void onClick(View v){
    switch (v.getId()){
        case R.id.banner:
            startActivity(new Intent(this,MainActivity.class));
            break;
        case R.id.register:
            registerUser();
            break;
    }
}

private void registerUser() {
    String email = editTextEmail.getText().toString().trim();
    String username = editTextTextPersonName2.getText().toString().trim();
    String fullname = editTextPersonName.getText().toString().trim();
    String password = editTextPassword.getText().toString().trim();

    if(fullname.isEmpty()){
        editTextPersonName.setError("Full name is required");
        editTextPersonName.requestFocus();
        return;
    }

    if(email.isEmpty()){
        editTextEmail.setError("Email is required");
        editTextEmail.requestFocus();
        return;
    }

    if(username.isEmpty()){
        editTextTextPersonName2.setError("Username is required");
        editTextTextPersonName2.requestFocus();
        return;
    }

    if(password.isEmpty()){
        editTextPassword.setError("Password is required");
        editTextPassword.requestFocus();
        return;
    }

    if(!Patterns.EMAIL_ADDRESS.matcher(email).matches()) {
        editTextEmail.setError("Please provide valid email!");
        editTextEmail.requestFocus();
        return;
    }

   if(password.length() < 6){
       editTextPassword.setError("Min password length should be 6 character!");
       editTextPassword.requestFocus();
       return;
   }

   mAuth.createUserWithEmailAndPassword(email,password).addOnCompleteListener(new OnCompleteListener<AuthResult>() {
       @Override
       public void onComplete(@NonNull Task<AuthResult> task) {
           if(task.isSuccessful()){
               User user = new User(fullname, username, email);

               FirebaseDatabase.getInstance().getReference("Users").child(FirebaseAuth.getInstance().getCurrentUser().getUid()).setValue(user).addOnCompleteListener(new OnCompleteListener<Void>() {
                   @Override
                   public void onComplete(@NonNull Task<Void> task) {
                       if(task.isSuccessful()){
                           Toast.makeText(RegisterUser.this,"User has been registered successfully",Toast.LENGTH_LONG).show();
                       }
                       else{
                           Toast.makeText(RegisterUser.this,"Failed to register! Try again!",Toast.LENGTH_LONG).show();
                       }
                   }
               });
           }
           else{
               Toast.makeText(RegisterUser.this,"Failed to register! Try again!",Toast.LENGTH_LONG).show();
           }
       }
   });

}

`

  • Is your app crashing? If yes, show us the entire message that you get. – Alex Mamo Oct 30 '21 at 08:11
  • no its not crashing – Kramerlle Oct 30 '21 at 11:38
  • How do you get the error? And what is the entire message of "Please change your database URL to ..."? – Alex Mamo Oct 30 '21 at 11:40
  • i get the error when i try to register the user and the Authentication is successfull but the database i still empthy. the exact error is: – Kramerlle Oct 30 '21 at 11:49
  • 2021-10-30 13:47:49.204 21891-21960/com.kramerlle.nodubts W/PersistentConnection: pc_0 - Firebase Database connection was forcefully killed by the server. Will not attempt reconnect. Reason: Database lives in a different region. Please change your database URL to https://nodubts-default-rtdb.europe-west1.firebasedatabase.app AND – Kramerlle Oct 30 '21 at 11:49
  • 2021-10-30 13:47:48.496 21891-21916/com.kramerlle.nodubts W/System: Ignoring header X-Firebase-Locale because its value was null. – Kramerlle Oct 30 '21 at 11:49
  • Please check the duplicate to see how you can solve that. – Alex Mamo Oct 30 '21 at 11:53

0 Answers0