java Android studio用户注册数据未插入firebase数据库
我上面的代码是将用户注册数据插入firebase数据库。但是,当我构建应用程序并尝试将一些演示数据插入数据库以执行用户注册时,没有一个数据被插入firebase。有人能检查我的代码,找出我做错了什么吗
public class CreateProfile extends AppCompatActivity {
EditText etName,etBio,etProfession,etEmail,etWeb;
Button button;
ImageView imageView;
ProgressBar progressBar;
Uri imageUri;
UploadTask uploadTask;
StorageReference storageReference;
FirebaseDatabase database = FirebaseDatabase.getInstance();
DatabaseReference databaseReference;
FirebaseFirestore db = FirebaseFirestore.getInstance() ;
DocumentReference documentReference;
private static final int PICK_IMAGE=1;
All_User_Member member;
String currentUserId;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_create_profile);
member = new All_User_Member();
imageView = findViewById(R.id.iv_cp);
etBio = findViewById(R.id.et_bio_cp);
etEmail = findViewById(R.id.et_email_cp);
etName = findViewById(R.id.et_name_cp);
etProfession = findViewById(R.id.et_profession_cp);
etWeb = findViewById(R.id.et_web_cp);
button = findViewById(R.id.btn_cp);
progressBar = findViewById(R.id.progressbar_cp);
FirebaseUser user = FirebaseAuth.getInstance().getCurrentUser();
currentUserId = user.getUid();
//reference
documentReference = db.collection("user").document(currentUserId);
storageReference = FirebaseStorage.getInstance().getReference("Profile images");
databaseReference = database.getReference("All users");
//button click
button.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
uploadData();
}
});
//ProfileImageSelect
imageView.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
Intent intent = new Intent();
intent.setType("image/*");
intent.setAction(Intent.ACTION_GET_CONTENT);
startActivityForResult(Intent.createChooser(intent,"select image"),PICK_IMAGE);
}
});
}
//LoadingProfileImage
@Override
protected void onActivityResult(int requestCode, int resultCode, @Nullable Intent data) {
super.onActivityResult(requestCode, resultCode, data);
try {
if (requestCode==PICK_IMAGE || resultCode== RESULT_OK || data != null || data.getData() !=null){
imageUri = data.getData();
Picasso.get().load(imageUri).into(imageView);
}
}catch (Exception e){
Toast.makeText(this, "Error"+e, Toast.LENGTH_SHORT).show();
}
}
private String getFileExt(Uri uri){
ContentResolver contentResolver = getContentResolver();
MimeTypeMap mimeTypeMap = MimeTypeMap.getSingleton();
return mimeTypeMap.getExtensionFromMimeType((contentResolver.getType(uri)));
}
private void uploadData() {
String name = etName.getText().toString();
String bio = etBio.getText().toString();
String web = etWeb.getText().toString();
String prof = etProfession.getText().toString();
String mail = etEmail.getText().toString();
if(TextUtils.isEmpty(name) || TextUtils.isEmpty(bio) || TextUtils.isEmpty(web) || TextUtils.isEmpty(prof) ||
TextUtils.isEmpty(mail) || imageUri != null){
progressBar.setVisibility(View.VISIBLE);
final StorageReference reference = storageReference.child(System.currentTimeMillis()+ "."+getFileExt(imageUri));
uploadTask = reference.putFile(imageUri);
Task<Uri> urlTask = uploadTask.continueWithTask(new Continuation<UploadTask.TaskSnapshot, Task<Uri>>() {
@Override
public Task<Uri> then(@NonNull Task<UploadTask.TaskSnapshot> task) throws Exception {
if (!task.isSuccessful()){
throw task.getException();
}
return reference.getDownloadUrl();
}
}).addOnCompleteListener(new OnCompleteListener<Uri>() {
@Override
public void onComplete(@NonNull Task<Uri> task) {
if (task.isSuccessful()){
Uri downloadUri = task.getResult();
Map<String, String> profile = new HashMap<>();
profile.put("name", name);
profile.put("prof", prof);
profile.put("url", downloadUri.toString());
profile.put("bio", bio);
profile.put("mail", mail);
profile.put("web", web);
profile.put("privacy", "Public");
member.setName(name);
member.setProf(prof);
member.setUid(currentUserId);
member.setUrl(downloadUri.toString());
databaseReference.child(currentUserId).setValue(member);
documentReference.set(profile).addOnSuccessListener(new OnSuccessListener<Void>() {
@Override
public void onSuccess(Void unused) {
progressBar.setVisibility(View.INVISIBLE);
Toast.makeText(CreateProfile.this, "Profile Created", Toast.LENGTH_SHORT).show();
Handler handler = new Handler();
handler.postDelayed(new Runnable() {
@Override
public void run() {
Intent intent = new Intent(CreateProfile.this,Fragment1.class);
startActivity(intent);
}
},2000);
}
});
}
}
});
}else {
Toast.makeText(this, "Please fill all fields", Toast.LENGTH_SHORT).show();
}
}
}
以下是安卓 studio中出现的错误:
共 (0) 个答案