用户成功注册并在Firebase中显示。但是,每次用户注册时,应用程序都会崩溃,尽管它可以在Firebase中成功注册。有没有我错误配置的东西?
reg.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
if(TextUtils.isEmpty(email.getText().toString())||TextUtils.isEmpty(password.getText().toString()))
Toast.makeText(getApplicationContext(),"Please fill in all the detail",Toast.LENGTH_SHORT).show();
else if(password.getError()!=null||email.getError()!=null)
Toast.makeText(getApplicationContext(),"Please fill in the detail correctly",Toast.LENGTH_SHORT).show();
else{
signUp( );
}
}
});
}
//Sign Up method
private void signUp() {
String e=email.getText().toString().trim();
String p=password.getText().toString().trim();
mAuth.createUserWithEmailAndPassword(e,p).addOnCompleteListener(this, new OnCompleteListener<AuthResult>() {
@Override
public void onComplete(@NonNull Task<AuthResult> task) {
Log.d("SIGNIN", "Sign up Successfully" + task.isSuccessful());
if (!task.isSuccessful()) {
Toast.makeText(RegisterActivity.this, "Signed up Failed", Toast.LENGTH_SHORT).show();
}
else{
createNewAccount(task.getResult().getUser());
}
}
});
}
我认为问题存在于此处
private void createNewAccount(FirebaseUser user) {
String username = name.getText().toString().trim();
int point=0;
String date1="None";
// Write new user
writeNewUser(user.getUid(), username, user.getEmail(),point,date1);
// Go to MainActivity
startActivity(new Intent(RegisterActivity.this, RewardGainActivity.class));
}
private void writeNewUser(String userId, String Uname, String eMail, int pointss, String date11) {
User user=new User(Uname,eMail,pointss,date11);
mDatabase.child("users").child(userId).setValue(user);
}
public class User {
public String uName2;
public String eMail2;
public int point2;
public String Date2;
public User() {
// Default constructor required for calls to DataSnapshot.getValue(User.class)
}
public User(String uName2, String eMail2, int point2, String Date2) {
this.uName2=uName2;
this.eMail2=eMail2;
this.point2=point2;
this.Date2=Date2;
}
}