NullPointerException在Android上拍照

时间:2015-04-16 13:50:54

标签: android bitmap nullpointerexception camera file-descriptor

我有一个应用程序可以在ImageView中制作照片和绘画。根据使用的设备,动作是否失败。我将错误返回到照片(NullPointerException)。有错误的设备有Android 4.2.2

protected void onActivityResult(int requestCode, int resultCode, 
        Intent imageReturnedIntent) {
    super.onActivityResult(requestCode, resultCode, imageReturnedIntent); 

    switch(requestCode) { 
    case ACTIVITY_SELECT_IMAGE:
        File imageFile = getTempFile();
        if(resultCode == RESULT_OK){  
            Bitmap bm = null;
            Uri selectedImage = null;
            if (imageReturnedIntent == null){    /** CAMERA **/

                selectedImage = Uri.fromFile(imageFile);
            }
            else{                                /** ALBUM **/
                selectedImage = imageReturnedIntent.getData();
            }

            int sampleSize = 7;
            do{
                sampleSize -= 2;
                bm = decodeBitmap(selectedImage, sampleSize);
            }while(bm.getWidth() < MIN_WIDTH_QUALITY && sampleSize > 1);
            saveBitmap(imageFile, bm);
            replaceImage(bm);

            saveLista();
        }
    }
}

private Bitmap decodeBitmap(Uri theUri, int sampleSize) {
    BitmapFactory.Options options = new BitmapFactory.Options();
    options.inSampleSize = sampleSize;

    AssetFileDescriptor fileDescriptor =null;
    try {
        fileDescriptor = this.getContentResolver().openAssetFileDescriptor( theUri, "r");
    } catch (FileNotFoundException e) {
        e.printStackTrace();
    }

    Bitmap actuallyUsableBitmap = BitmapFactory.decodeFileDescriptor(
            fileDescriptor.getFileDescriptor(), null, options);

    return actuallyUsableBitmap;
}

theUri = file:///mnt/sdcard/Android/data/com.XXX.XXX/files/552f5980e610620bd8e803ab/UserImages/19/19.png

fileDescriptor.getFileDescriptor() = null

04-16 15:46:39.686: E/AndroidRuntime(4194): Caused by: java.lang.NullPointerException
04-16 15:46:39.686: E/AndroidRuntime(4194):     at XXX.XXX.XXX.decodeBitmap(ModuleListaCompraFotografia.java:212)
04-16 15:46:39.686: E/AndroidRuntime(4194):     at XXX.XXX.XXX.onActivityResult(ModuleListaCompraFotografia.java:188)
04-16 15:46:39.686: E/AndroidRuntime(4194):     at android.app.Activity.dispatchActivityResult(Activity.java:5293)
04-16 15:46:39.686: E/AndroidRuntime(4194):     at android.app.ActivityThread.deliverResults(ActivityThread.java:3315)

0 个答案:

没有答案