在三星Galaxy S5(Android 4.4.2)上安装完成后,我点击该应用程序,然后崩溃了。崩溃堆栈是
08-18 13:58:48.191 10816-10851/com.example.galina.demo W/ContextImpl: Unable to create files directory /data/data/com.example.galina.demo/files
08-18 13:58:48.191 10816-10816/com.example.galina.demo E/AndroidRuntime: FATAL EXCEPTION: main
Process: com.example.galina.demo, PID: 10816
java.lang.RuntimeException: Unable to create application com.example.galina.demo.MainApplication: java.lang.NullPointerException
at android.app.ActivityThread.handleBindApplication(ActivityThread.java:4752)
at android.app.ActivityThread.access$1600(ActivityThread.java:172)
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1368)
at android.os.Handler.dispatchMessage(Handler.java:102)
at android.os.Looper.loop(Looper.java:146)
at android.app.ActivityThread.main(ActivityThread.java:5653)
at java.lang.reflect.Method.invokeNative(Native Method)
at java.lang.reflect.Method.invoke(Method.java:515)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:1291)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:1107)
at dalvik.system.NativeStart.main(Native Method)
Caused by: java.lang.NullPointerException
at com.example.cll.android.AndroidCll.<init>(AndroidCll.java:42)
at com.example.util.telemetry.CllLogger.<init>(CllLogger.java:113)
at com.example.util.TTLCoreImpl.initialize(TTLCoreImpl.java:134)
at com.example.util.core.TTLCore.initialize(TTLCore.java:24)
at com.example.galina.demo.MainApplication.onCreate(MainApplication.java:25)
at android.app.Instrumentation.callApplicationOnCreate(Instrumentation.java:1013)
at android.app.ActivityThread.handleBindApplication(ActivityThread.java:4749)
at android.app.ActivityThread.access$1600(ActivityThread.java:172)
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1368)
at android.os.Handler.dispatchMessage(Handler.java:102)
at android.os.Looper.loop(Looper.java:146)
at android.app.ActivityThread.main(ActivityThread.java:5653)
at java.lang.reflect.Method.invokeNative(Native Method)
at java.lang.reflect.Method.invoke(Method.java:515)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:1291)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:1107)
at dalvik.system.NativeStart.main(Native Method)
MainApplication.java正在开始工作,它有很多代码...... AndroidCll.java:42的行是
String dataPath = context.getFilesDir().getPath();
context
null。
来自MainApplication.onCreate()的getApplicationContext()传入context
。
上下文为空的原因是由未捕获的异常导致的vm关闭,此异常与Unable to create files directory /data/data/com.example.galina.demo/files
有关
我检查了目录/数据/数据/,没有文件夹com.microsoft.mmx.sdkdemo
。它并不是每次都会发生,但很有可能发生。我在这个设备上测试其他应用程序,没问题。它无法创建这个目录,这很奇怪。
答案 0 :(得分:-1)
您必须通过在AndroidManifest.xml文件中添加uses-permission条目来通知Android您的应用程序需要写入外部存储。
<uses-permission android:name="android.permission.WRITE_INTERNAL_STORAGE"/>