現在、firebaseデータベースに名前、電子メール、パスワード、年齢を正常に挿入していますが、選択したラジオボタンから値を挿入しようとするまで、悪夢が私に届きました。問題はデータがデータベースに挿入されることがありますが、認証部分でさえも挿入できないため、この問題をどのように解決できるのでしょうか?なぜfirabase認証からのgetidにエラーがありますか?
public class Register extends AppCompatActivity {
private FirebaseAuth auth;
private EditText run, rpw,re;
private EditText rpn, ra, rpc;
private TextView rage;
private String usnm, pswd, email, age, uid;
private FirebaseDatabase db;
private DatabaseReference ref;
private DatePickerDialog.OnDateSetListener dsl;
@Override
protected void onCreate(Bundle savedInstanceState){
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_register);
auth = FirebaseAuth.getInstance();
db = FirebaseDatabase.getInstance();
ref = db.getReference();
FirebaseUser ur = auth.getCurrentUser();
uid = ur.getUid();//getuser id
run = (EditText) findViewById(R.id.Run);
rpw = (EditText) findViewById(R.id.Rpw);
rage = (TextView) findViewById(R.id.Rage);
rage.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
Calendar mc = Calendar.getInstance();
int y = mc.get(Calendar.YEAR);
int m = mc.get(Calendar.MONTH);
int day = mc.get(Calendar.DAY_OF_MONTH);
DatePickerDialog dpd = new DatePickerDialog(Register.this,
android.R.style.Theme_Holo_Dialog_MinWidth, dsl, y, m, day);
dpd.getDatePicker().setMaxDate(mc.getTimeInMillis());
dpd.getWindow().setBackgroundDrawable(new ColorDrawable(Color.TRANSPARENT));
dpd.show();
}
});
dsl = new DatePickerDialog.OnDateSetListener() {
@Override
public void onDateSet(DatePicker view, int year, int month, int dayOfMonth) {
month = month+1;
String date = dayOfMonth +"/" + month + "/" +year;
rage.setText(date);
}
};
re = (EditText) findViewById(R.id.Re);
rpn = (EditText) findViewById(R.id.Rpn);
ra = (EditText) findViewById(R.id.Ra);
rpc = (EditText) findViewById(R.id.Rpc);
//rbstd = (RadioButton) findViewById(R.id.rbstd);
//rbtt= (RadioButton) findViewById(R.id.rbtt);
final Button br = (Button) findViewById(R.id.Rbt);
br.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
usnm = run.getText().toString().trim();
pswd = rpw.getText().toString().trim();
email = re.getText().toString().trim();
age = rage.getText().toString().trim();
validateUsername(usnm);
if(TextUtils.isEmpty(pswd)){
Toast.makeText(Register.this, "Password cannot be empty", LENGTH_SHORT).show();
return;
}else if (pswd.length()<8){
Toast.makeText(Register.this, "Password cannot less then 8 characters", LENGTH_SHORT).show();
return;
}else if (pswd.length()>12){
Toast.makeText(Register.this, "Password cannot greater then 12 characters", LENGTH_SHORT).show();
return;
}else if (TextUtils.isEmpty(age)){
Toast.makeText(Register.this, "Please select date", LENGTH_SHORT).show();
return;
}
validateEmail(email);
register(usnm, pswd, age, email);
}//end of onclick
});
}
private void register (final String un, final String pw, final String ag, final String em){
Task<AuthResult> authResultTask = auth.createUserWithEmailAndPassword(em, pw).addOnCompleteListener(new OnCompleteListener<AuthResult>() {
@Override
public void onComplete(@NonNull Task<AuthResult> task) {
if (task.isSuccessful()) {
//insertion
User u = new User (un, pw, ag, em);
ref.child(uid).setValue(u);
//prompt message
Toast.makeText(Register.this, "Success Registration", Toast.LENGTH_LONG).show();
Intent i = new Intent(Register.this, StudentHomePage.class);
startActivity(i);
finish();
} else {
Toast.makeText(Register.this, "Registration Error", Toast.LENGTH_LONG).show();
Intent i = new Intent(Register.this, Login.class);
startActivity(i);
finish();
}
}
});
}// end of signup
private void validateUsername(final String validateName){
if (TextUtils.isEmpty(validateName)){
Toast.makeText(Register.this, "Username cannot be empty", LENGTH_SHORT).show();
return;
}else if (validateName.length()<8){
Toast.makeText(Register.this, "Username cannot less then 8 characters", LENGTH_SHORT).show();
return;
}else if (validateName.length()>12){
Toast.makeText(Register.this, "Username cannot greater then 12 characters", LENGTH_SHORT).show();
return;
}else {
ref.child(uid).orderByChild("username").equalTo(validateName).addValueEventListener(new ValueEventListener() {
@Override
public void onDataChange(DataSnapshot dataSnapshot) {
if (dataSnapshot!=null && dataSnapshot.getChildren()!=null && dataSnapshot.hasChild(validateName)){
Toast.makeText(Register.this, "Username had been taken", LENGTH_SHORT).show();
return;
}else{
Toast.makeText(Register.this, "Username unique", LENGTH_SHORT).show();
return;
}
}
@Override
public void onCancelled(DatabaseError databaseError) {
Toast.makeText(Register.this, "Database Connection Error", LENGTH_SHORT).show();
return;
}
});
}
}
private void validateEmail(final String valiemail){
if (TextUtils.isEmpty(valiemail)){
Toast.makeText(Register.this, "Username cannot be empty", LENGTH_SHORT).show();
return;
}else {
ref.child(uid).orderByChild("email").equalTo(valiemail).addValueEventListener(new ValueEventListener() {
@Override
public void onDataChange(DataSnapshot dataSnapshot) {
if (dataSnapshot!=null && dataSnapshot.getChildren()!=null && dataSnapshot.hasChild(valiemail)){
Toast.makeText(Register.this, "Email had been taken", LENGTH_SHORT).show();
return;
}else{
Toast.makeText(Register.this, "Email unique", LENGTH_SHORT).show();
return;
}
}
@Override
public void onCancelled(DatabaseError databaseError) {
Toast.makeText(Register.this, "Database Connection Error",
LENGTH_SHORT).show();
return;
}
});
}
}
}
logcatは
のjava.lang.NullPointerExceptionを示しています、引数 'pathString' の
をnullを渡すことはできません。この問題を解決するために私をアドバイスしてください。 挿入するときにアプリケーションが動作しなくなり、今度はレジスタページ全体が表示されなくなりました。
ただし、リスナーはどこに挿入しますか? –
あなたの活動の 'onCreate'にはそれが問題ありません。 –
09-03 13:19:18.136 17404-17422/com.example.rex.ota30 W/DynamiteModule:com.google.firebase.authのローカルモジュール記述子クラスが見つかりません。 –