gpt4 book ai didi

android - ActivityThread.handleBindApplication 中的 NullPointerException

转载 作者:太空狗 更新时间:2023-10-29 16:05:53 25 4
gpt4 key购买 nike

我收到了这份堆栈跟踪报告,其中根本没有提及我的应用:

java.lang.NullPointerException
at android.app.ActivityThread.handleBindApplication(ActivityThread.java:3979)
at android.app.ActivityThread.access$1300(ActivityThread.java:130)
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1255)
at android.os.Handler.dispatchMessage(Handler.java:99)
at android.os.Looper.loop(Looper.java:137)
at android.app.ActivityThread.main(ActivityThread.java:4745)
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:786)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:553)
at dalvik.system.NativeStart.main(Native Method)

有人知道如何防止这种异常吗?

最佳答案

一如既往,当发生这种情况时,我必须深入研究 Android 源代码来评估问题,我想我会在这里发布我的发现,这样可以节省其他人的时间。

此错误对应于 4.1.1_r1 中的此代码和 4.1.2_r1 :

    final ContextImpl appContext = new ContextImpl();
appContext.init(data.info, null, this);
final File cacheDir = appContext.getCacheDir();

// Provide a usable directory for temporary files
System.setProperty("java.io.tmpdir", cacheDir.getAbsolutePath()); // line 3979

setupGraphicsSupport(data.info, cacheDir);

发生这种情况是因为 appContext.getCacheDir()在某些情况下返回 null:

@Override
public File getCacheDir() {
synchronized (mSync) {
if (mCacheDir == null) {
mCacheDir = new File(getDataDirFile(), "cache");
}
if (!mCacheDir.exists()) {
if(!mCacheDir.mkdirs()) {
Log.w(TAG, "Unable to create cache directory");
return null;
}
FileUtils.setPermissions(
mCacheDir.getPath(),
FileUtils.S_IRWXU|FileUtils.S_IRWXG|FileUtils.S_IXOTH,
-1, -1);
}
}
return mCacheDir;
}

相关: https://groups.google.com/forum/?fromgroups=#!topic/android-developers/-694j87eXVU


然而,这似乎4.2.1 版本中得到了正确处理:

    final ContextImpl appContext = new ContextImpl();
appContext.init(data.info, null, this);
if (!Process.isIsolated()) {
final File cacheDir = appContext.getCacheDir();

if (cacheDir != null) {
// Provide a usable directory for temporary files
System.setProperty("java.io.tmpdir", cacheDir.getAbsolutePath());

setupGraphicsSupport(data.info, cacheDir);
} else {
Log.e(TAG, "Unable to setupGraphicsSupport due to missing cache directory");
}
}

关于android - ActivityThread.handleBindApplication 中的 NullPointerException,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/15326780/

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