上传图片到Firebase的问题

我试图从手机的图库上传图片到Firebase,但模拟器保持关闭状态,并且没有记录任何错误。 这是我的代码

val PICK_IMAGE_CODE=123 fun loadImage(){ var intent = Intent(Intent.ACTION_PICK,MediaStore.Images.Media.EXTERNAL_CONTENT_URI) startActivityForResult(intent,PICK_IMAGE_CODE) } override fun onActivityResult(requestCode: Int, resultCode: Int, data: Intent?) { super.onActivityResult(requestCode, resultCode, data) if(requestCode==PICK_IMAGE_CODE && data!=null && resultCode == RESULT_OK){ val selectedImage=data.data val filePathColum= arrayOf(MediaStore.Images.Media.DATA) val cursor= contentResolver.query(selectedImage,filePathColum,null,null,null) cursor.moveToFirst() val coulomIndex=cursor.getColumnIndex(filePathColum[0]) val picturePath=cursor.getString(coulomIndex) cursor.close() uploadImage(BitmapFactory.decodeFile(picturePath)) } } var DownloadURL:String?="" fun uploadImage(bitmap:Bitmap){ adapter!!.notifyDataSetChanged() var currentUser = mAuth!!.currentUser val storage= FirebaseStorage.getInstance() val storgaRef=storage.reference val df= SimpleDateFormat("ddMMyyHHmmss") val dataobj= Date() val imagePath= currentUser!!.uid+ "."+ df.format(dataobj)+ ".jpg" val ImageRef=storgaRef.child("imagePost/"+imagePath ) val baos= ByteArrayOutputStream() bitmap.compress(Bitmap.CompressFormat.JPEG,100,baos) val data= baos.toByteArray() val uploadTask=ImageRef.putBytes(data) uploadTask.addOnFailureListener{ Toast.makeText(applicationContext,"fail to upload", Toast.LENGTH_LONG).show() }.addOnSuccessListener { taskSnapshot -> DownloadURL= taskSnapshot.downloadUrl!!.toString() ListTweets.removeAt(0) adapter!!.notifyDataSetChanged() } } 

如果我注释掉我为uploadImage所做的调用,模拟器不会崩溃,所以我认为我得到的图片路径有一些问题,但我不确定。 谁能帮我吗?

    我想通了,我没有要求权限,所以我使用的picturePath始终为空