I'm just wanna create an account with some data. Unfortunately, I do not know where the error is, and during registration, the account is created but the data is not saved in the Realtime Database.
mAuth.createUserWithEmailAndPassword(email, password).addOnCompleteListener(task -> {
if (task.isSuccessful()) {
FirebaseUser user = mAuth.getCurrentUser();
reference = FirebaseDatabase.getInstance().getReference("Users").child(user.getUid());
HashMap<String, Object> hashMap = new HashMap<>();
hashMap.put("username", username);
hashMap.put("email", email);
hashMap.put("id", user.getUid());
hashMap.put("imageURL", "default");
hashMap.put("status", "offline");
reference.setValue(hashMap).addOnCompleteListener(task1 -> {
if (task1.isSuccessful()) {
Toast.makeText(RegisterActivity.this, "Registered Successfully", Toast.LENGTH_SHORT).show();
startActivity(new Intent(RegisterActivity.this, StartActivity.class).addFlags(Intent.FLAG_ACTIVITY_CLEAR_TASK | Intent.FLAG_ACTIVITY_NEW_TASK));
}else{
Toast.makeText(RegisterActivity.this, "Registered Failed", Toast.LENGTH_SHORT).show();
}
});
}
});