gpt4 book ai didi

java - getResources 返回 null

转载 作者:太空宇宙 更新时间:2023-11-03 10:48:50 24 4
gpt4 key购买 nike

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

但是一些用户报告崩溃报告是这样的:

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

It is not easy to reappear this crash. We think a lot about this problem. We receive a
uninstall event ,then the Application context Class called it's onCreate method, we do some initial works there , when we call getResouce(), it returns null . When look deep inside the framework codes, we find that getReource locate resources file by sourceDir String in ApplicationInfo, and the String is "/data/app/com.cm.mg-1.apk" > it's the original apk , and it is not exists anymore.

这可能发生在用户更新我们的应用程序时。以某种方式“/data/app/com.cm.mg-1.apk”已经被删除并以任何方式替换为“/data/app/com.cm.mg-2.apk”,但是“sourceDir”字符串在 ApplicationInfo 中没有更新。

I want to know what android does when doing a updating.

最佳答案

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

RuntimeException: Unable to instantiate application

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

关于java - getResources 返回 null,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/17692891/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com