Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/android/205.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/7/image/5.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Android 相机应用程序。创建文件以将其保存到存储器时出错_Android_Image_File_Save_Android Camera - Fatal编程技术网

Android 相机应用程序。创建文件以将其保存到存储器时出错

Android 相机应用程序。创建文件以将其保存到存储器时出错,android,image,file,save,android-camera,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{

我不知道为什么,但当我尝试拍照时,我遇到了这个错误:

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

感谢您的帮助:)

是否确实创建了文件或抛出了
IOException
?当发生错误时,它会创建一个文件并抛出一个IOEception发生错误?它说该文件为空…您知道如何将相机图像保存在存储器中吗?