Moin Moin ich schreibe gerade ein Login und eine Registrierung leider habe ich wen ich die Methode .getUid() nutze einen Nullpointer der es mir nicht möglich macht einen Button mit Male or Female funktionstüchtig einzufügen.
Java: RegisterActivity
public class RegisterActivity extends AppCompatActivity {
private Button regi_btn;
private EditText umail, upass,upass_conf, uFirstname, uName, uDate, uPhone;
private ProgressDialog loading;
private RadioGroup uRadioGroup;
private FirebaseAuth mAuth;
private FirebaseAuth.AuthStateListener mAuthStateListener;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_register);
regi_btn = findViewById(R.id.btn_reg);
umail = findViewById(R.id.email);
upass = findViewById(R.id.pass);
uName = findViewById(R.id.uname);
uRadioGroup = findViewById(R.id.radioGroup);
mAuth = FirebaseAuth.getInstance();
mAuthStateListener = new FirebaseAuth.AuthStateListener() {
@Override
public void onAuthStateChanged(@NonNull FirebaseAuth firebaseAuth) {
final FirebaseUser user = FirebaseAuth.getInstance().getCurrentUser();
if(user != null){
Intent intent4 = new Intent(RegisterActivity.this,MainActivity.class);
startActivity(intent4);
finish();
return;
}
}
};
regi_btn.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
final String name = uName.getText().toString();
final String email = umail.getText().toString();
final String pass = upass.getText().toString();
int selectID = uRadioGroup.getCheckedRadioButtonId();
final RadioButton radioButton = findViewById(selectID);
if(radioButton.getText() == null){
return;
}
mAuth.createUserWithEmailAndPassword(email, pass).addOnCompleteListener(RegisterActivity.this, new OnCompleteListener<AuthResult>() {
@Override
public void onComplete(@NonNull Task<AuthResult> task) {
if(!task.isSuccessful()){
Toast.makeText(RegisterActivity.this, "sign_up_error" , Toast.LENGTH_SHORT).show();
}else{
try {
String userID = mAuth.getCurrentUser().getUid();
DatabaseReference currentUserDb = FirebaseDatabase.getInstance().getReference().child("Users").child(radioButton.getText().toString())
.child(userID).child("name");
currentUserDb.setValue(name);
}catch(NullPointerException e){
e.printStackTrace();
}
}
}
});
}
});
}
@Override
protected void onStart() {
super.onStart();
mAuth.addAuthStateListener(mAuthStateListener);
}
@Override
protected void onStop() {
super.onStop();
mAuth.removeAuthStateListener(mAuthStateListener);
}
}
Display More