科特林"Destructuring declaration initializer of type String must have a 'component1()' function"



我是这样调用这个函数的:-

val (ImageUrl: String) = uploadImage("ImageTitle", imageTitleUri!!)

这是函数代码:-

private fun uploadImage(ImageName: String, ImageUri: Uri): String {
val fileRef = storagePicRef!!.child("$ImageName.jpg")
val uploadTask: StorageTask<*>
uploadTask = fileRef.putFile(ImageUri)
var imageURL = ""

uploadTask.continueWithTask(com.google.android.gms.tasks.Continuation<UploadTask.TaskSnapshot, Task<Uri>> { task ->
if (!task.isSuccessful) {
task.exception?.let {
throw it
}
}
return@Continuation fileRef.downloadUrl
}).addOnCompleteListener { task ->
if (task.isSuccessful) {
val downloadUrl = task.result
imageURL = downloadUrl.toString()
}
Toast.makeText(baseContext, "Uploaded successfully.", Toast.LENGTH_SHORT).show()
}
return imageURL
}

这就是我如何试图获得图像Url。但是我得到这个错误:-

"Destructuring declaration initializer of type String must have a 'component1()' function"

我看到了其他类似的问题,但这里的返回值只是字符串类型的一个。所以,我可以直接使用它

删除这些括号(ImageUrl: String),它会工作好,

所以你的函数调用应该是这样的:

val ImageUrl: String = uploadImage("ImageTitle", imageTitleUri!!)

还建议以小写字母开始变量,因此将其命名为imageUrl而不是ImageUrl

相关内容

最新更新