我想实现将图像和视频上传到Firebase。我使用了两个称为onSaveInstanceState()
和onRestoreInstanceState()
的方法来保存变量。有用! ..但是当活动旋转时,会出现如下错误
这是我的代码:
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()
}
答案 0 :(得分:0)
您不应使用断言运算符(!!)。这是错误的最大原因。而是可以使用安全呼叫运算符(?)或猫王运算符(?:)。
我认为,您需要有关Kotlin Null安全性的更多信息。您可以访问此网站Null Safety。