0

I don't know why but I'am getting this error when I try to take a Picture:

java.lang.NullPointerException: file
at android.net.Uri.fromFile(Uri.java:452)
at zockerbros.com.chatapp.main.Chat_Room.onClick(Chat_Room.java:547)

Code for creating File:

File createFile() throws IOException{                                   
String timeStamp = new SimpleDateFormat("yyyMMMddd_HHmmss").format(newDate());
String imageFileName = "IMG_"+timeStamp+"_";
File StorgaeDirectory = Environment.getExternalStoragePublicDirectory(Environment.DIRECTORY_PICTURES);

File image = File.createTempFile(imageFileName, ".jpg", StorgaeDirectory);
mImageFileLocation = image.getAbsolutePath();
galleryAddPic(mImageFileLocation);
return image;}

Code for taking the Picture:

Intent callCameraAppIntent = new Intent();
            callCameraAppIntent.setAction(MediaStore.ACTION_IMAGE_CAPTURE);

            File photoFile = null;
            try{
                photoFile = createFile();

            }catch(IOException e){
                e.printStackTrace();
            }
            -> Here is the error callCameraAppIntent.putExtra(MediaStore.EXTRA_OUTPUT, Uri.fromFile(photoFile));

            startActivityForResult(callCameraAppIntent, TAKE_PICTURE);

Thanks for your help :)

Phantômaxx
  • 37,901
  • 21
  • 84
  • 115
Zocker Bros
  • 173
  • 1
  • 1
  • 9

0 Answers0