Android - > onActivityResult->处理图像 - >某些设备上的空指针异常

时间:2014-01-26 17:18:23

标签: android nullpointerexception photo

我注意到,我的应用程序在 onActivityResult 方法中的某些设备上崩溃。

我试图解决这个问题,但没有运气,没有人知道,会导致这个问题的原因是什么?在以下方法中,我在某些设备上始终存在IO异常(例如HUAWEI ASCEND P6)。

@Override
protected void onActivityResult(int requestCode, int resultCode, Intent data) { 
    if (requestCode == REQUEST_IMAGE_CAPTURE && resultCode == RESULT_OK) {
        try {
            Log.i(GlobalApplication.APP_LOG_NAMESPACE, "Trying to process image");
            GlobalApplication globalAppClass = ((GlobalApplication) getApplicationContext());
            AppHelper helper = new AppHelper();
            Bundle extras = data.getExtras();
            Bitmap imageBitmap = (Bitmap) extras.get("data");
            Uri imageUri = data.getData();
            Bitmap bitmap;
            Bitmap resizedBitmap;
            String timeStamp = new SimpleDateFormat("yyyyMMdd_HHmmss").format(new Date());
            String imageFileName = "DAMAGE_" + globalAppClass.getEanCode() + "_" + timeStamp + ".jpg";
            String dirname =  "smartt/"+globalAppClass.getEanCode();

            bitmap = MediaStore.Images.Media.getBitmap(this.getContentResolver(), imageUri);
            resizedBitmap = helper.getResizedBitmap(bitmap, 768, 1024);
            helper.createDirectoryAndSaveImage(resizedBitmap, imageFileName, dirname);
            // place thumbnail into image view
            //mImageView.setImageBitmap(imageBitmap);

            TextView photoCountTv = (TextView)findViewById(R.id.damageReportTakenPhotosCountTv);
            photoCountTv.setText(R.string.foto_attached);
            photoCountTv.setTextColor(getResources().getColor(R.color.green));

            TextView dataPassingTv = (TextView)findViewById(R.id.damageReportPassingTitle);
            dataPassingTv.setText(R.string.data_passing);
            dataPassingTv.setTextColor(getResources().getColor(R.color.green));

        } catch (FileNotFoundException e) {
            Log.e(GlobalApplication.APP_LOG_NAMESPACE, "onActivityResult method cannot be processed, file not found", e);
            e.printStackTrace();
        } catch (IOException e) {
            Log.e(GlobalApplication.APP_LOG_NAMESPACE, "onActivityResult method cannot be processed, IOE Exception", e);
            e.printStackTrace();
        } catch (Exception e) {
            Log.e(GlobalApplication.APP_LOG_NAMESPACE, "onActivityResult method cannot be processed, IOE Exception", e);
            e.printStackTrace();
        }
    }
}

感谢您的任何想法。

1 个答案:

答案 0 :(得分:0)

我会检查你的所有资源是否到位。请记住,IDE经常为不同的屏幕尺寸创建替代目录(例如 drawable-hdpi,drawable-xhdpi 等)。检查,如果配置失败,将使用哪种屏幕。

您还可以在此处查看:http://developer.android.com/guide/topics/resources/providing-resources.html