我正在尝试将图片uri存储在我的Firebase数据库中,但它始终采用onFailure
方法。 onSucess
方法中的Uri数据始终为null。我已经尝试了所有的解决方案,但没有任何解决方案。
auth.createUserWithEmailAndPassword(email, password)
.addOnCompleteListener(SignupActivity.this, new OnCompleteListener<AuthResult>() {
@Override
public void onComplete(@NonNull Task<AuthResult> task) {
Toast.makeText(SignupActivity.this, "createUserWithEmail:onComplete:" + task.isSuccessful(), Toast.LENGTH_SHORT).show();
progressBar.setVisibility(View.GONE);
// If sign in fails, display a message to the user. If sign in succeeds
// the auth state listener will be notified and logic to handle the
// signed in user can be handled in the listener.
if (!task.isSuccessful()) {
Toast.makeText(SignupActivity.this, "Authenticationfailed." + task.getException(),
Toast.LENGTH_SHORT).show();
} else {
onAuthSuccess(task.getResult().getUser());
finish();
}
}
});
}
});
}
private void onAuthSuccess(FirebaseUser user) {
String username = usernameFromEmail(user.getEmail());
if(result != null) {
firebase_Storage = FirebaseStorage.getInstance().getReference().child("Profile").child(user.getUid());
Bitmap bitmap = null;
try {
bitmap = MediaStore.Images.Media.getBitmap(getApplication().getContentResolver(),result);
} catch (Exception e) {
e.printStackTrace();
}
ByteArrayOutputStream byteArrayOutputStream = new ByteArrayOutputStream();
bitmap.compress(Bitmap.CompressFormat.JPEG,20,byteArrayOutputStream);
byte[] data = byteArrayOutputStream.toByteArray();
UploadTask uploadTask = firebase_Storage.putBytes(data);
uploadTask.addOnSuccessListener(new OnSuccessListener<UploadTask.TaskSnapshot>() {
@Override
public void onSuccess(UploadTask.TaskSnapshot taskSnapshot) {
Log.e("InsideOnSuccess",taskSnapshot.getDownloadUrl().toString());
uri_data = taskSnapshot.getDownloadUrl();
}
}).addOnFailureListener(new OnFailureListener() {
@Override
public void onFailure(@NonNull Exception e) {
Log.e("Failed","Failed");
}
});
writeNewUser(name,user.getUid(), user.getEmail());
}
主要任务是获取URI并保存到Firebase数据库中。但我在做这件事时遇到了这个问题。有什么建议我怎么办?
编辑: - 我在onFailure方法中遇到此异常消息:&#34;对象在位置不存在。&#34;