错误:找不到符号downloadUrl = task.getResult()。getDownloadUrl()。toString();

时间:2020-04-30 02:17:34

标签: java

以下行存在错误。

找不到符号downloadUrl = task.getResult()。getDownloadUrl()。toString();

private void StoringImageToFirebaseStorage() {
    Calendar calFordData = Calendar.getInstance();
    SimpleDateFormat currentDate = new SimpleDateFormat("dd-MMMM-yyyy");
    saveCurrentData = currentDate.format(calFordData.getTime());

    Calendar calFordTime = Calendar.getInstance();
    SimpleDateFormat currentTime = new SimpleDateFormat("HH:mm");
    saveCurrentTime = currentTime.format(calFordData.getTime());

    postRandomName = saveCurrentData + saveCurrentTime;

    StorageReference filePath = PostsImagesRefrence.child("Post Images").child(ImageUri.getLastPathSegment()+ postRandomName + ".jpg");

    filePath.putFile(ImageUri).addOnCompleteListener(new OnCompleteListener<UploadTask.TaskSnapshot>() {
        @Override
        public void onComplete(@NonNull Task<UploadTask.TaskSnapshot> task) {
            if (task.isSuccessful())
            {
                downloadUrl = task.getResult().getDownloadUrl().toString();
                Toast.makeText(PostActivity.this, "Image uploaded successfully to storage", Toast.LENGTH_SHORT).show();

                SavingPostInformationToDatabase();
            }
            else{
                String message = task.getException().getMessage();
                Toast.makeText(PostActivity.this, "Error Occurred", Toast.LENGTH_SHORT).show();
            }
        }
    });
}

2 个答案:

答案 0 :(得分:0)

将downloadUrl声明为字符串。

<body onload="PR.prettyPrint()">
<pre class="prettyprint linenums lang-html">
    &lt;script type=&quot;text/javascript&quot;&gt;
    // Say hello world until the user starts questioning
    // the meaningfulness of their existence.
    function helloWorld(world) {
      for (var i = 42; --i &gt;= 0;) {
        alert('Hello ' + String(world));
      }
    }
    &lt;/script&gt;
    &lt;style&gt;
    p { color: pink }
    b { color: blue }
    u { color: &quot;umber&quot; }
    &lt;/style&gt;
</pre>
</body>

答案 1 :(得分:0)

您可以这样做:

filePath.getDownloadUrl().addOnSuccessListener(new OnSuccessListener<Uri>() {
                    @Override
                    public void onSuccess(Uri uri) {
                        downloadUrl =  uri.toString();
                        SavingPostInformationToDatabase();
                        Toast.makeText(PostActivity.this, "Image uploaded successfully to storage", Toast.LENGTH_SHORT).show();

                    }
                });