0
I’m having the following error while loading image gallery or smartphone camera. And I can’t find where this error because it only happens on some smartphone models.
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.Ismiss()' 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)
My code below:
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();
}
}
"'void android.app.Progressdialog.Dismiss()' on a null Object Reference at " try to check if your 'pDialog' is null before using the Dismiss method
– Alessandro Barreto
pDialog = new Progressdialog(Perfil_activity.this); pDialog.Dismiss(); this giving error why this pDialog line is null, the pDialog variable is declared in the general body of Activity???
– Rodrigo Costa