0

赋值不是表达式,在这种情况下只允许表达式我不知道如何解决这个问题

private  fun uploadImageToFirebaswStorage(){
    if (selectedphotoUri = null) return
    val filename = UUID.randomUUID().toString()
     val ref = FirebaseStorage.getInstance().getReference("/images/$filename")

    ref.putFile(selectedphotoUri!!)
        .addOnSuccessListener {
            Log.d("Register","Successfully uploaded image: ${it.metadata?.path}")}
4

2 回答 2

1

selectedphotoUri = null是一个任务。最有可能的是,您想要selectedphotoUri == null(两个等号),即等式表达式。

于 2019-08-31T17:30:31.307 回答
0

假设您想像 CommonsWare 指出的那样进行相等性检查,另一种选择是使用涉及let的常见Kotlin 习语

值 = ...

value?.let { ... // 如果不为 null 则执行此块 }

private  fun uploadImageToFirebaswStorage(){
    selectedphotoUri?.let {
        val filename = UUID.randomUUID().toString()
        val ref = FirebaseStorage.getInstance().getReference("/images/$filename")    
        ref.putFile(selectedphotoUri!!)
          .addOnSuccessListener {
              Log.d("Register","Successfully uploaded image: ${it.metadata?.path}")
          }
     }
}  
于 2019-08-31T23:57:56.947 回答