无法在图像视图中设置Firebase图像Uri

时间:2017-11-06 06:16:01

标签: android firebase firebase-realtime-database

我正在尝试使用Glide将Image从FIrebase设置为Imageview,但它显示错误

Task<Uri> riversRef = storageReference.child(user.getUid() + "/profile.jpg").getDownloadUrl()
                    .addOnSuccessListener(new OnSuccessListener<Uri>() {
                        @Override
                        public void onSuccess(Uri uri) {
                            if (uri == null) {
                                Toast.makeText(getApplicationContext(), "URI IS NULL", Toast.LENGTH_LONG).show();
                            }
                            Glide.with(getContext()).load(uri).centerCrop().into(imageView);
                        }
                    });

错误是:

  

进程:com.root.firebase,PID:3875                                                                    java.lang.NullPointerException:尝试调用虚方法   '对象上的'boolean android.app.Activity.isDestroyed()'   参考                                                                        在   com.bumptech.glide.manager.RequestManagerRetriever.assertNotDestroyed(RequestManagerRetriever.java:133)                                                                        在   com.bumptech.glide.manager.RequestManagerRetriever.get(RequestManagerRetriever.java:125)                                                                        在com.bumptech.glide.Glide.with(Glide.java:641)                                                                        在   com.root.firebase.UploadActivity $ 2.onSuccess(UploadActivity.java:72)                                                                        在   com.root.firebase.UploadActivity $ 2.onSuccess(UploadActivity.java:65)                                                                        在com.google.android.gms.tasks.zzj.run(未知来源)                                                                        在android.os.Handler.handleCallback(Handler.java:751)                                                                        在android.os.Handler.dispatchMessage(Handler.java:95)                                                                        在android.os.Looper.loop(Looper.java:154)                                                                        在android.app.ActivityThread.main(ActivityThread.java:6077)                                                                        at java.lang.reflect.Method.invoke(Native Method)                                                                        在   com.android.internal.os.ZygoteInit $ MethodAndArgsCaller.run(ZygoteInit.java:866)                                                                        在com.android.internal.os.ZygoteInit.main(ZygoteInit.java:756)

1 个答案:

答案 0 :(得分:1)

Task<Uri> riversRef = storageReference.child(user.getUid() + "/profile.jpg").getDownloadUrl()
                .addOnSuccessListener(new OnSuccessListener<Uri>() {
                    @Override
                    public void onSuccess(Uri uri) {
                        Toast.makeText(getApplicationContext(), "GET IMAGE SUCCESSFUL", Toast.LENGTH_LONG).show();
                        if (uri == null) {
                            Toast.makeText(getApplicationContext(), "URI IS NULL", Toast.LENGTH_LONG).show();
                        }
               else{         Glide.with(getContext()).load(uri).centerCrop().into(imageView);}
                    }
                }).addOnFailureListener(new OnFailureListener() {
                    @Override
                    public void onFailure(@NonNull Exception exception) {
                        Toast.makeText(getApplicationContext(), "GET IMAGE FAILED", Toast.LENGTH_LONG).show();
                        // Handle any errors
                    }
                });