请帮助我解决此问题。当我选择要上传的图片时,应用崩溃。现在已经几天了,我仍然遇到这个问题。
Log.d指向
uploadProfileCoverPhoto(image_uri);
storageReference2nd.putFile(uri)
确实需要您的帮助。谢谢
@Override
public void onActivityResult(int requestCode, int resultCode, Intent data) {
//Calling a method for after picking image from gallery or camera
if (resultCode == RESULT_OK)
if (requestCode == IMAGE_PICK_GALLERY_CODE){
Log.d(TAG, "onActivityResult: " + data);
//Image is picked from gallery, get uri of the image
image_uri = data.getData();
uploadProfileCoverPhoto(image_uri);
}
if (requestCode == IMAGE_PICK_CAMERA_CODE){
//Image is picked from camera, get uri of the image
uploadProfileCoverPhoto(image_uri);
}
super.onActivityResult(requestCode, resultCode, data);
}
private void uploadProfileCoverPhoto(Uri uri) {
//Show progress Bar
LoadingBar.setVisibility(View.VISIBLE);
//Path and the name of image to be stored in firebase storage
String filePathAndName = storagePath + "" + profileOrCoverPhoto + "_" + user.getUid();
StorageReference storageReference2nd = storageReference.child(filePathAndName);
storageReference2nd.putFile(uri)
.addOnSuccessListener(new OnSuccessListener<UploadTask.TaskSnapshot>() {
@Override
public void onSuccess(UploadTask.TaskSnapshot taskSnapshot) {
Log.d(TAG, "onSuccess: " + taskSnapshot);
//Image has been uploaded to storage. Get its url and store it to Db
Task<Uri> uriTask = taskSnapshot.getStorage().getDownloadUrl();
while (!uriTask.isSuccessful());
Uri downloadUri = uriTask.getResult();
//Check if image is uploaded and its url received or not
if (uriTask.isSuccessful()){
//Image uploaded
//Update user's Db with the image
HashMap<String, Object> results = new HashMap<>();
results.put(profileOrCoverPhoto, downloadUri.toString());
databaseReference.child(user.getUid()).updateChildren(results)
.addOnSuccessListener(new OnSuccessListener<Void>() {
@Override
public void onSuccess(Void aVoid) {
Log.d(TAG, "onSuccess:");
//url in Db of the user is added successfully
LoadingBar.setVisibility(View.INVISIBLE);
Toast.makeText(getActivity(), "Image updeted successfully", Toast.LENGTH_SHORT).show();
}
})
.addOnFailureListener(new OnFailureListener() {
@Override
public void onFailure(@NonNull Exception e) {
Log.d(TAG, "onFailure: " + e);
//Some error occured
LoadingBar.setVisibility(View.INVISIBLE);
Toast.makeText(getActivity(), "Error occured...", Toast.LENGTH_LONG).show();
}
});
}
else {
//Error occured
LoadingBar.setVisibility(View.INVISIBLE);
Toast.makeText(getContext(), "!Oops. Image upload failed", Toast.LENGTH_LONG).show();
}
}
})
.addOnFailureListener(new OnFailureListener() {
@Override
public void onFailure(@NonNull Exception e) {
Log.d(TAG, "onFailure: " + e);
//Error occured so show the error msg to the user
LoadingBar.setVisibility(View.INVISIBLE);
Toast.makeText(getActivity(), e.getMessage(), Toast.LENGTH_LONG).show();
}
});
}
请在下面显示日志消息。这是我第一次问关于stackoverflow的问题,所以如果我不能遵守任何规定的规则,请原谅我
Logcat:
2019-06-21 18:02:25.528 13198-13198/com.example.skulmunsem D/AndroidRuntime: Shutting down VM
2019-06-21 18:02:25.540 13198-13198/com.example.skulmunsem E/AndroidRuntime: FATAL EXCEPTION: main
Process: com.example.skulmunsem, PID: 13198
java.lang.RuntimeException: Failure delivering result ResultInfo{who=null, request=65836, result=-1, data=Intent { dat=content://com.google.android.apps.photos.contentprovider/-1/1/content://media/external/images/media/690/ORIGINAL/NONE/1059317505 flg=0x1 clip={text/uri-list U:content://com.google.android.apps.photos.contentprovider/-1/1/content%3A%2F%2Fmedia%2Fexternal%2Fimages%2Fmedia%2F690/ORIGINAL/NONE/1059317505} }} to activity {com.example.skulmunsem/com.example.skulmunsem.ProfileActivity}: java.lang.IllegalArgumentException: Volume external not found
at android.app.ActivityThread.deliverResults(ActivityThread.java:4639)
at android.app.ActivityThread.handleSendResult(ActivityThread.java:4681)
at android.app.servertransaction.ActivityResultItem.execute(ActivityResultItem.java:51)
at android.app.servertransaction.TransactionExecutor.executeCallbacks(TransactionExecutor.java:135)
at android.app.servertransaction.TransactionExecutor.execute(TransactionExecutor.java:95)
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1940)
at android.os.Handler.dispatchMessage(Handler.java:106)
at android.os.Looper.loop(Looper.java:209)
at android.app.ActivityThread.main(ActivityThread.java:7046)
at java.lang.reflect.Method.invoke(Native Method)
at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:486)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:862)
Caused by: java.lang.IllegalArgumentException: Volume external not found
at android.database.DatabaseUtils.readExceptionFromParcel(DatabaseUtils.java:170)
at android.database.DatabaseUtils.readExceptionWithFileNotFoundExceptionFromParcel(DatabaseUtils.java:151)
at android.content.ContentProviderProxy.openTypedAssetFile(ContentProviderNative.java:705)
at android.content.ContentResolver.openTypedAssetFileDescriptor(ContentResolver.java:1653)
at android.content.ContentResolver.openAssetFileDescriptor(ContentResolver.java:1475)
at android.content.ContentResolver.openFileDescriptor(ContentResolver.java:1316)
at android.content.ContentResolver.openFileDescriptor(ContentResolver.java:1270)
at com.google.firebase.storage.UploadTask.<init>(com.google.firebase:firebase-storage@@17.0.0:120)
at com.google.firebase.storage.StorageReference.putFile(com.google.firebase:firebase-storage@@17.0.0:260)
at com.example.skulmunsem.Fragment.ProfileFragment.uploadProfileCoverPhoto(ProfileFragment.java:534)
at com.example.skulmunsem.Fragment.ProfileFragment.onActivityResult(ProfileFragment.java:512)
at androidx.fragment.app.FragmentActivity.onActivityResult(FragmentActivity.java:160)
at android.app.Activity.dispatchActivityResult(Activity.java:7966)
at android.app.ActivityThread.deliverResults(ActivityThread.java:4632)
at android.app.ActivityThread.handleSendResult(ActivityThread.java:4681)
at android.app.servertransaction.ActivityResultItem.execute(ActivityResultItem.java:51)
at android.app.servertransaction.TransactionExecutor.executeCallbacks(TransactionExecutor.java:135)
at android.app.servertransaction.TransactionExecutor.execute(TransactionExecutor.java:95)
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1940)
at android.os.Handler.dispatchMessage(Handler.java:106)
at android.os.Looper.loop(Looper.java:209)
at android.app.ActivityThread.main(ActivityThread.java:7046)
at java.lang.reflect.Method.invoke(Native Method)
at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:486)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:862)
2019-06-21 18:02:25.602 13198-13198/com.example.skulmunsem I/Process: Sending signal. PID: 13198 SIG: 9