的時候我會在我註冊數據添加到數據庫中,但我得到了
火力地堡.getUID NullPointerException異常認證介紹
顯示java.lang.NullPointerException:試圖調用虛擬方法java.lang.String中com.google.firebase。 auth.FirebaseUser.getUid()」空引用對象上的
我試一下,但是不工作
這裏是我的代碼
auth = FirebaseAuth.getInstance();
database = FirebaseDatabase.getInstance();
mRef = database.getReference();
FirebaseUser user = auth.getCurrentUser();
userID = user.getUid();
btnSignUp.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
final String fname = etFname.getText().toString().trim();
final String lname = etLname.getText().toString().trim();
final String id_card = etIdCard.getText().toString().trim();
final String email = etEmail.getText().toString().trim();
final String mobile = etMobile.getText().toString().trim();
String password = etPassword.getText().toString().trim();
if (TextUtils.isEmpty(email)){
Toast.makeText(getApplicationContext(), "Enter email address!", Toast.LENGTH_SHORT).show();
return;
}
if (TextUtils.isEmpty(password)){
Toast.makeText(getApplicationContext(), "Enter password!", Toast.LENGTH_SHORT).show();
return;
}
if (TextUtils.isEmpty(fname)){
Toast.makeText(getApplicationContext(), "Enter FirstName!", Toast.LENGTH_SHORT).show();
return;
}
if (password.length() < 8) {
Toast.makeText(getApplicationContext(), "Password too short, enter minimum 8 characters!", Toast.LENGTH_SHORT).show();
return;
}
progressBar.setVisibility(View.VISIBLE);
auth.createUserWithEmailAndPassword(email,password)
.addOnCompleteListener(new OnCompleteListener<AuthResult>() {
@Override
public void onComplete(@NonNull Task<AuthResult> task) {
if (!task.isSuccessful()) {
UserInfo userInfo = new UserInfo(fname,lname,id_card,mobile,email);
mRef.child("users").child(userID).setValue(userInfo);
etFname.setText("");
etLname.setText("");
etIdCard.setText("");
etMobile.setText("");
etEmail.setText("");
Toast.makeText(RegisterActivity.this, "Authentication failed." + task.getException(),
Toast.LENGTH_SHORT).show();
} else {
Toast.makeText(RegisterActivity.this, "Register Successfully" + task.isSuccessful(), Toast.LENGTH_SHORT).show();
progressBar.setVisibility(View.GONE);
finish();
}
}
});
}
});
}
現在得到像這樣的新錯誤 java.lang.NoSuchMethodError:在類Lcom/google/firebase/FirebaseApp中沒有虛方法zzTt()Z;或其超類(「com.google.firebase.FirebaseApp」的聲明出現在/data/app/com.example.androiddev.army31-1/split_lib_dependencies_apk.apk:classes36.dex)
現在我可以修復它因爲gradle這個不是同一版本
編譯,得到了相同的事情
感謝答覆遺憾吶如何使用您的代碼?我不確定 –
單個班輪和他做了什麼之間的區別是什麼?沒有,這是基本的Java –
請參考文檔完整的工作代碼Java中[email protected] – Pheonix