我得到
java.lang.IllegalStateException:任务尚未完成
第val result = url.result
行出现错误。
这里怎么了?
这是我的代码:
riversRef.putFile(filePath!!).addOnSuccessListener(
{ taskSnapshot ->
progressDial.dismiss()
Toast.makeText(this,"Successfully uploaded",Toast.LENGTH_SHORT).show()
val url = taskSnapshot.storage.downloadUrl
val result = url.result // ERROR occurs here !!!
val imagePath = result.toString()
mstorage!!.push().setValue(imagePath)
})
.addOnFailureListener( {
Toast.makeText(this,"Upload Failed",Toast.LENGTH_SHORT).show()
})
.addOnProgressListener {
val progress = (100.0*it.bytesTransferred/it.totalByteCount)
progressDial.setMessage("Uploaded "+progress+"%")
}
答案 0 :(得分:-1)
像这样放入while((!! uri.isComplete()))。
reference.putFile(file).addOnSuccessListener(new OnSuccessListener<UploadTask.TaskSnapshot>() {
@Override
public void onSuccess(UploadTask.TaskSnapshot taskSnapshot) {
toast("Entered success listner");
Task<Uri> uri = taskSnapshot.getStorage().getDownloadUrl();
while ((!uri.isComplete()));
Uri url = uri.getResult();
databaseReference = FirebaseDatabase.getInstance().getReference("uploads");
PDFDoc uploadpdf = new PDFDoc(name.getText().toString(), url.toString());
databaseReference.child(databaseReference.push().getKey()).setValue(uploadpdf);
toast("Uploaded to database");
progressDialog.dismiss();
}
})
这对我有用:)