相机应用程序创建文件以将其保存在存储上时出错

时间:2017-04-22 10:07:44

标签: android image file save android-camera

我不知道为什么但是当我尝试拍照时我收到此错误:

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

创建文件的代码:

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;}

拍摄照片的代码:

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);

感谢您的帮助:)

0 个答案:

没有答案