Estou tendo o seguinte erro ao carregar galeria de imagem ou câmera smartphone. E eu não consigo encontrar onde este erro porque isso só acontece em alguns modelos de smartphones.
java.lang.RuntimeException: Unable to resume activity {br.com.curriculo/br.com.curriculo.Perfil_Activity}: java.lang.RuntimeException: Failure delivering result ResultInfo{who=null, request=4000, result=-1, data=Intent { dat=content://media/external/images/media/5636 flg=0x1 }} to activity {br.com.curriculo/br.com.curriculo.Perfil_Activity}: java.lang.NullPointerException: Attempt to invoke virtual method 'void android.app.ProgressDialog.dismiss()' on a null object reference at android.app.ActivityThread.performResumeActivity(ActivityThread.java:3121) at android.app.ActivityThread.handleResumeActivity(ActivityThread.java:3152) at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2495) at android.app.ActivityThread.-wrap11(ActivityThread.java) at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1354) at android.os.Handler.dispatchMessage(Handler.java:102) at android.os.Looper.loop(Looper.java:148) at android.app.ActivityThread.main(ActivityThread.java:5443) at java.lang.reflect.Method.invoke(Native Method) at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:728) at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:618) Caused by: java.lang.RuntimeException: Failure delivering result ResultInfo{who=null, request=4000, result=-1, data=Intent { dat=content://media/external/images/media/5636 flg=0x1 }} to activity {br.com.curriculo/br.com.curriculo.Perfil_Activity}: java.lang.NullPointerException: Attempt to invoke virtual method 'void android.app.ProgressDialog.dismiss()' on a null object reference at android.app.ActivityThread.deliverResults(ActivityThread.java:3720) at android.app.ActivityThread.performResumeActivity(ActivityThread.java:3107) ... 10 more Caused by: java.lang.NullPointerException: Attempt to invoke virtual method 'void android.app.ProgressDialog.dismiss()' on a null object reference at br.com.curriculo.mecontrate.Perfil_Activity.onActivityResult(Perfil_Activity.java:589) at android.app.Activity.dispatchActivityResult(Activity.java:6442) at android.app.ActivityThread.deliverResults(ActivityThread.java:3716)
Meu código abaixo:
public void opengalleryProfile(){
pDialog = new ProgressDialog(Perfil_Activity.this);
pDialog.setMessage(Perfil_Activity.this.getString(R.string.aguarde));
pDialog.setIndeterminate(true);
pDialog.setCancelable(true);
pDialog.show();
Intent i = new Intent(
Intent.ACTION_PICK, android.provider.MediaStore.Images.Media.EXTERNAL_CONTENT_URI);
startActivityForResult(i, GALERIA_PERFIL);
}
public void openCamera(){
NomeArquivo = DateFormat.format(
"dd-MM-yyyy hh_mm_ss", new Date()).toString();
File picsDir = Environment.getExternalStoragePublicDirectory(getString(R.string.app_name) + File.separator + getString(R.string.app_name)+" "+ getString(R.string.pasta_imagens) );
imageFile = new File(picsDir,NomeArquivo +".jpg");
Intent intent = new Intent(android.provider.MediaStore.ACTION_IMAGE_CAPTURE);
intent.putExtra(MediaStore.EXTRA_OUTPUT, Uri.fromFile(imageFile));
startActivityForResult(intent, CAMERA_PERFIL);
}
@Override
protected void onActivityResult(int requestCode, int resultCode, Intent data) {
if (requestCode == GALERIA_PERFIL){
pDialog.dismiss();
if (resultCode == RESULT_OK && data != null) {
try {
mImageCaptureUri = data.getData();
performCropPerfil(mImageCaptureUri);
} catch (Exception e) {
Toast.makeText(this, R.string.falhaImagem,
Toast.LENGTH_SHORT).show();
}
}
}
if (requestCode == CAMERA_PERFIL){
if ( resultCode == RESULT_OK && imageFile != null) {
try {
performCropPerfil(Uri.fromFile(imageFile));
} catch (Exception e) {
Toast.makeText(this, R.string.falhaImagem,
Toast.LENGTH_SHORT).show();
}
}
}
if (requestCode == CROP_FROM_CAMERA) {
if ( resultCode == RESULT_OK && data != null) {
Bundle extras = data.getExtras();
if (extras != null) {
try {
bmpArquivo = extras.getParcelable("data");
imgPerfil.setImageBitmap(bmpArquivo);
} catch (Exception e) {
Toast.makeText(this, R.string.falhaImagem,
Toast.LENGTH_SHORT).show();
}
}
}
}
}
private void performCropPerfil(Uri uri) {
try {
Intent cropIntent = new Intent("com.android.camera.action.CROP");
cropIntent.setDataAndType(uri, "image/*");
cropIntent.putExtra("scale", true);
cropIntent.putExtra("aspectX", 1);
cropIntent.putExtra("aspectY", 1);
cropIntent.putExtra("outputX",128);
cropIntent.putExtra("outputY", 128);
cropIntent.putExtra("return-data", true);
startActivityForResult(cropIntent, CROP_FROM_CAMERA);
}
catch (ActivityNotFoundException anfe) {
Toast toast = Toast
.makeText(this, R.string.falhaCortarImagem, Toast.LENGTH_SHORT);
toast.show();
}
}