第七色在线视频,2021少妇久久久久久久久久,亚洲欧洲精品成人久久av18,亚洲国产精品特色大片观看完整版,孙宇晨将参加特朗普的晚宴

為了賬號(hào)安全,請(qǐng)及時(shí)綁定郵箱和手機(jī)立即綁定
已解決430363個(gè)問(wèn)題,去搜搜看,總會(huì)有你想問(wèn)的

從圖庫(kù)中選擇的圖像出現(xiàn) Kotlin 錯(cuò)誤

從圖庫(kù)中選擇的圖像出現(xiàn) Kotlin 錯(cuò)誤

天涯盡頭無(wú)女友 2022-11-02 16:02:23
我無(wú)法加載所選圖像。正在加載默認(rèn)模板圖像。我用帖子中的完整片段代碼對(duì)其進(jìn)行了編輯,您能指導(dǎo)我使用哪個(gè)參數(shù)上傳到所選圖像嗎?以下更新的代碼有效,但僅上傳預(yù)定義的圖像,我無(wú)法上傳選定的圖像,我不知道該行使用哪個(gè)參數(shù)if (this.imageUri != imageUri && requestCode == IMAGE_PICK_CODE && resultCode == RESULT_OK) {class  ReportFragment : Fragment(), OnMapReadyCallback, GoogleMap.OnMapClickListener, GoogleMap.OnCameraIdleListener {    private var mMapView: MapView? = null    private var map: GoogleMap? = null    val CAMERA_PERMISSION_CODE = 0    val CAMERA_REQUEST_CODE = 10    lateinit var imageFilePath: String    private var imgThumb: ImageView? = null    private var spinner: Spinner? = null    private var currentLocation: LatLng? = null  // TODO: get current location as static variable    private var midLatLng: LatLng? = null    private var lat: Double? = null    private var lng: Double? = null    private var objectValues: Array<String>? = null    private var imageUri: Uri? = null    private var pictureTaken: Boolean = false    private var progress: ProgressBar? = null    val PERMISSION_CODE_READ = 1001    val PERMISSION_CODE_WRITE = 1002    val IMAGE_PICK_CODE = 1000    private val database: FirebaseDatabase? = FirebaseDatabase.getInstance()    private val markersRef: DatabaseReference? = database!!.getReference("markers")    private val storage = FirebaseStorage.getInstance()    private val storageRef: StorageReference = storage.reference    private var imagesRef: StorageReference? = null    private val permissoes = arrayOf(Manifest.permission.READ_EXTERNAL_STORAGE)    inner class GenericFileProvider : FileProvider()
查看完整描述

1 回答

?
斯蒂芬大帝

TA貢獻(xiàn)1827條經(jīng)驗(yàn) 獲得超8個(gè)贊

這是一個(gè)空指針異常。imageUri 為空


MediaStore.Images.Media.getBitmap(context.contentResolver, this.imageUri) as Bitmap

如果您檢查 getBitmap() 的實(shí)現(xiàn)。



public static final Bitmap getBitmap(ContentResolver cr, Uri url)

                throws FileNotFoundException, IOException {

            InputStream input = cr.openInputStream(url);

            Bitmap bitmap = BitmapFactory.decodeStream(input);

            input.close();

            return bitmap;

        }

你會(huì)發(fā)現(xiàn)它調(diào)用了 openInputStream() ,它需要一個(gè)非空的 uri。


public final @Nullable InputStream openInputStream(@NonNull Uri uri)



   override fun onActivityResult(requestCode: Int, resultCode: Int, data: Intent?) {

        super.onActivityResult(requestCode, resultCode, data)

        if (this.imageUri != null && requestCode == IMAGE_PICK_CODE && resultCode == RESULT_OK) {


            try {

                //Getting the Bitmap from Gallery

                val bitmap = MediaStore.Images.Media.getBitmap(context.contentResolver, this.imageUri) as Bitmap

                this.imgThumb!!.setImageBitmap(bitmap)

                this.pictureTaken = true

            } catch (e:IOException) {

                e.printStackTrace()

            }

        } else {

            Toast.makeText(context, "Error loading image", Toast.LENGTH_LONG)

        }

    }


查看完整回答
反對(duì) 回復(fù) 2022-11-02
  • 1 回答
  • 0 關(guān)注
  • 128 瀏覽
慕課專欄
更多

添加回答

舉報(bào)

0/150
提交
取消
微信客服

購(gòu)課補(bǔ)貼
聯(lián)系客服咨詢優(yōu)惠詳情

幫助反饋 APP下載

慕課網(wǎng)APP
您的移動(dòng)學(xué)習(xí)伙伴

公眾號(hào)

掃描二維碼
關(guān)注慕課網(wǎng)微信公眾號(hào)