无法在android

时间:2016-06-06 07:52:28

标签: android android-studio

我在使用以下代码创建目录时遇到问题。我在我的清单中有这个:

<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" />

这是创建目录的代码:

        File mediaStorageDir = new File(Environment.getExternalStorageDirectory() + "/app");
    if (! mediaStorageDir.exists()){
        if (! mediaStorageDir.mkdirs()){
            Log.d("MyCameraApp", "failed to create directory");
            return null;
        }
    }

当我尝试运行该应用时,这是完整的错误:

  

06-06 00:48:25.054 19696-19696 / com.cameraApp.cameratest D / MyCameraApp:创建目录失败   06-06 00:48:25.054 19696-19696 / com.cameraApp.cameratest D / AndroidRuntime:关闭VM   06-06 00:48:25.054 19696-19696 / com.cameraApp.cameratest E / AndroidRuntime:FATAL EXCEPTION:main                                                                                处理:com.cameraApp.cameratest,PID:19696                                                                                java.lang.RuntimeException:无法启动活动ComponentInfo {com.cameraApp.cameratest / com.cameraApp.cameratest.MainActivity}:java.lang.NullPointerException:file                                                                                    在android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2416)                                                                                    在android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2476)                                                                                    在android.app.ActivityThread.-wrap11(ActivityThread.java)                                                                                    在android.app.ActivityThread $ H.handleMessage(ActivityThread.java:1344)                                                                                    在android.os.Handler.dispatchMessage(Handler.java:102)                                                                                    在android.os.Looper.loop(Looper.java:148)                                                                                    在android.app.ActivityThread.main(ActivityThread.java:5417)                                                                                    at java.lang.reflect.Method.invoke(Native Method)                                                                                    在com.android.internal.os.ZygoteInit $ MethodAndArgsCaller.run(ZygoteInit.java:726)                                                                                    在com.android.internal.os.ZygoteInit.main(ZygoteInit.java:616)                                                                                 引起:java.lang.NullPointerException:file                                                                                    在android.net.Uri.fromFile(Uri.java:452)                                                                                    在com.cameraApp.cameratest.MainActivity.getOutputMediaFileUri(MainActivity.java:101)                                                                                    在com.cameraApp.cameratest.MainActivity.onCreate(MainActivity.java:45)                                                                                    在android.app.Activity.performCreate(Activity.java:6237)                                                                                    在android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1107)                                                                                    在android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2369)                                                                                    在android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2476)                                                                                    在android.app.ActivityThread.-wrap11(ActivityThread.java)                                                                                    在android.app.ActivityThread $ H.handleMessage(ActivityThread.java:1344)                                                                                    在android.os.Handler.dispatchMessage(Handler.java:102)                                                                                    在android.os.Looper.loop(Looper.java:148)                                                                                    在android.app.ActivityThread.main(ActivityThread.java:5417)                                                                                    at java.lang.reflect.Method.invoke(Native Method)                                                                                    在com.android.internal.os.ZygoteInit $ MethodAndArgsCaller.run(ZygoteInit.java:726)                                                                                    在com.android.internal.os.ZygoteInit.main(ZygoteInit.java:616)

帮助。 :(

0 个答案:

没有答案