i have following Problem with my app: When i take a foto with the camera and press the SEND TO EMAIL Button it all works fine, the picture is saved on the phone and it is loading up to my email Intent. BUT when i take NO image and i press the SEND TO EMAIL Button the app crashes ! Could someone Help me out ??
The Email Intent Code:
emailIntent.putExtra(Intent.EXTRA_STREAM, Uri.fromFile(foto));
The Camera Intent Code:
FotoButton = (Button) findViewById(R.id.FotoButton);
FotoButton.setOnClickListener(new View.OnClickListener() {
public void onClick(View v) {
startCamera();
}
});
}
private void startCamera() {
Intent intent = new Intent(MediaStore.ACTION_IMAGE_CAPTURE);
foto = new File(Environment.getExternalStoragePublicDirectory(Environment.DIRECTORY_PICTURES), "Fehlerbild.jpg");
Uri image = Uri.fromFile(foto);
intent.putExtra(MediaStore.EXTRA_OUTPUT, image);
startActivityForResult(intent,TAKE_FOTO);
The Crashed Code:
04-02 11:57:30.229 21042-21042/de.cmoreno.hcsedv_service E/AndroidRuntime: FATAL EXCEPTION: main
Process: de.cmoreno.hcsedv_service, PID: 21042
java.lang.NullPointerException: file
at android.net.Uri.fromFile(Uri.java:448)
at de.cmoreno.hcsedv_service.Main2Activity$1.onClick(Main2Activity.java:174)
at android.view.View.performClick(View.java:5242)
at android.widget.TextView.performClick(TextView.java:10573)
at android.view.View$PerformClick.run(View.java:21196)
at android.os.Handler.handleCallback(Handler.java:739)
at android.os.Handler.dispatchMessage(Handler.java:95)
at android.os.Looper.loop(Looper.java:145)
at android.app.ActivityThread.main(ActivityThread.java:6938)
at java.lang.reflect.Method.invoke(Native Method)
at java.lang.reflect.Method.invoke(Method.java:372)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:1404)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:1199)