如何从android studio中的firabase存储获取下载url

goqiplq2  于 2021-08-20  发布在  Java
关注(0)|答案(0)|浏览(194)

我试图从存储器下载url,但应用程序总是崩溃。当我调试代码时,我在哪一行发现了错误,但idk如何在logcat中修复它,它表示任务尚未完成。这是我的代码,我从中获得下载url

uploadTask.addOnSuccessListener(new OnSuccessListener<UploadTask.TaskSnapshot>() {
                    @Override
       \\THIS LINE          public void onSuccess(UploadTask.TaskSnapshot taskSnapshot) {
                            storageReference.getDownloadUrl().addOnSuccessListener(new OnSuccessListener<Uri>() {
                                @Override
                                public void onSuccess(Uri uri) {
                                    String downloaduri = uri.toString();
                                    Map newimage = new HashMap();
                                    newimage.put("profileImageUri", downloaduri);
                                    reference.child("Customer").child(userID).updateChildren(newimage);
                                    finish();
                                }
                            });
                    }
                });

这就是当应用程序崩溃时我在日志中看到的

--------- beginning of crash
E/AndroidRuntime: FATAL EXCEPTION: main
    Process: com.example.deliveryapp, PID: 2824
    java.lang.IllegalArgumentException: getDownloadUrl() is not supported at the root of the bucket.
        at com.google.firebase.storage.GetDownloadUrlTask.<init>(GetDownloadUrlTask.java:46)
        at com.google.firebase.storage.StorageReference.getDownloadUrl(StorageReference.java:370)
        at com.example.deliveryapp.Profile2$5.onSuccess(Profile2.java:131)
        at com.example.deliveryapp.Profile2$5.onSuccess(Profile2.java:128)
        at com.google.firebase.storage.StorageTask.lambda$new$0$StorageTask(StorageTask.java:123)
        at com.google.firebase.storage.-$$Lambda$StorageTask$xlHsb5OfSRp-di5vg8sdDdXsCO4.raise(Unknown Source:6)
        at com.google.firebase.storage.TaskListenerImpl.lambda$onInternalStateChanged$2$TaskListenerImpl(TaskListenerImpl.java:90)
        at com.google.firebase.storage.-$$Lambda$TaskListenerImpl$S8elBxPWPDCBbbHv0Z6yA1jvX68.run(Unknown Source:6)
        at android.os.Handler.handleCallback(Handler.java:938)
        at android.os.Handler.dispatchMessage(Handler.java:99)
        at android.os.Looper.loop(Looper.java:223)
        at android.app.ActivityThread.main(ActivityThread.java:7656)
        at java.lang.reflect.Method.invoke(Native Method)
        at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:592)
        at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:947)

暂无答案!

目前还没有任何答案,快来回答吧!

相关问题