致命异常:main,kotlin.KotlinNullPointerException

时间:2019-01-04 16:54:16

标签: android kotlin

我想实现将图像和视频上传到Firebase。我使用了两个称为onSaveInstanceState()onRestoreInstanceState()的方法来保存变量。有用! ..但是当活动旋转时,会出现如下错误

Logcat Error

这是我的代码:

storage = FirebaseStorage.getInstance()
storageReference = storage?.getReferenceFromUrl("gs://mypublicservice-98437.appspot.com/complain_images/")
storageReference2 = storage?.getReferenceFromUrl("gs://mypublicservice-98437.appspot.com/complain_videos/")

var pDialog = ProgressDialog(this)
pDialog.setTitle("Uploading...")
pDialog.setCancelable(true)
pDialog.show()
val childref = storageReference2?.child(videouri!!.lastPathSegment)
val childref2 = storageReference?.child(fp!!.lastPathSegment) // this is line 194
val uploadTask = childref?.putFile(videouri!!)
val uploadTask2 = childref2?.putFile(fp!!)

uploadTask2?.addOnSuccessListener {
    uploadTask?.addOnSuccessListener {

    }
    pDialog.dismiss()
    var builder = AlertDialog.Builder(this@ComplainActivity)
    builder.setTitle("Complain has been submitted !")
        /* .setPositiveButton("ok"){dialog, id:Int->
         finish()
     }*/
        .setNeutralButton("ok") { dialog, which ->

        }
        .create().show()
}

image of a larger piece of code

1 个答案:

答案 0 :(得分:0)

您不应使用断言运算符(!!)。这是错误的最大原因。而是可以使用安全呼叫运算符(?)或猫王运算符(?:)。

我认为,您需要有关Kotlin Null安全性的更多信息。您可以访问此网站Null Safety