task.getResult()引发ClassCastException

时间:2019-12-04 23:04:16

标签: java android firebase firebase-storage

我正在使用此代码来检索存储在Firebase存储器中的图像的Uri并将此图像检索到用户piture中,这是我的代码:

final  StorageReference fileReference = storageReference.child(System.currentTimeMillis()
                    + "." + getFileExtension(imgUri));

            uploadTask = fileReference.putFile(imgUri);
           uploadTask.continueWith(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 fileReference.getDownloadUrl();
               }
           }).addOnCompleteListener(new OnCompleteListener<Uri>(){
               @Override
               public void onComplete(@NonNull Task<Uri> task) {
                   if(task.isSuccessful()){

                       Uri downloadUri =  task.getResult();
                       String mUri = downloadUri.toString();

                       reff = FirebaseDatabase.getInstance().getReference().child("Users")
                               .child(FirebaseAuth.getInstance().getCurrentUser().getUid())
                       .child("Information");
                       HashMap<String,Object> map = new HashMap<>();
                       map.put("ImageURL",mUri);
                       reff.updateChildren(map);

它抛出此错误:java.lang.ClassCastException:com.google.android.gms.tasks.zzu无法转换为android.net.Uri

解决方案是什么?

0 个答案:

没有答案