繁体   English   中英

getResources返回null

[英]getResources returns null

我们注册广播接收器以接收包安装或卸载事件。

但有些用户报告崩溃报告如下:

java.lang.RuntimeException: Unable to create application com.kc.security.MoSecurityApplication: java.lang.RuntimeException: getResources is null: dir - /data/app/com.cm.mg-1.apk, srcVal-1, srcVal-2
at android.app.LoadedApk.makeApplication(LoadedApk.java:495)
at android.app.ActivityThread.handleCreateService(ActivityThread.java:2249)
at android.app.ActivityThread.access$1600(ActivityThread.java:123)
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1201)
at android.os.Handler.dispatchMessage(Handler.java:99)
at android.os.Looper.loop(Looper.java:137)
at android.app.ActivityThread.main(ActivityThread.java:4424)
at java.lang.reflect.Method.invokeNative(Native Method)
at java.lang.reflect.Method.invoke(Method.java:511)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:784)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:551)
at dalvik.system.NativeStart.main(Native Method)
Caused by: java.lang.RuntimeException: getResources is null: dir - /data/app/com.cm.mg-1.apk, srcVal-1, srcVal-2
at com.kc.security.b.ab.b(UpdateManager.java:69)
at com.kc.security.b.ab.a(UpdateManager.java:112)
at com.kc.security.MoSecurityApplication.onCreate(MoSecurityApplication.java:66)
at android.app.Instrumentation.callApplicationOnCreate(Instrumentation.java:969)
at android.app.LoadedApk.makeApplication(LoadedApk.java:492)
... 11 more

重现这次崩溃并不容易。 我们对这个问题有很多想法。 我们收到了
卸载事件,然后Application上下文类调用它的onCreate方法,我们在那里做一些初始工作,当我们调用getResouce()时,它返回null。 当深入了解框架代码时,我们发现getReource在ApplicationInfo中通过sourceDir String找到资源文件,而String是“/data/app/com.cm.mg-1.apk”>它是原始的apk,它是不再存在了。

当用户更新我们的应用程序时可能会发生 在某种程度上“/data/app/com.cm.mg-1.apk”已经全部删除并以“/data/app/com.cm.mg-2.apk”替换,但是“sourceDir”字符串在ApplicationInfo中没有更新。

我想知道android在进行更新时会做什么。

遇到类似的问题,看看这个。

RuntimeException:无法实例化应用程序

我认为这应该回答这个问题,可能是因为在此卸载事件期间资源已被销毁。

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM