检索失败在包图标 [英] Failure retrieving icon in package
问题描述
我的Android应用程序最近显示了一些奇怪的行为。下面包含的NullPointerException仅在特定设备抛出,例如采用Android 2.3.4一个摩托罗拉Defy装置产生此异常。虽然它工作正常上一个升级Froyo 2.3.6 Nexus One和2.2。 HTC Desire的,以及在Honeycomb平板电脑。有趣的是,我没有在任何地方访问APPICON自己在code。这里是堆栈跟踪,由摩托罗拉Defy抛出:
my Android app recently shows some strange behavior. The below included NullPointerException is thrown only on specific devices, for example a Motorola Defy device with Android 2.3.4 produces this Exception. Although it works fine on a Froyo 2.3.6 Nexus One and 2.2. HTC Desire, as well on Honeycomb tablet devices. The interesting thing is, I do not access the AppIcon myself anywhere in the code. Here is the Stack trace, thrown by the Motorola Defy:
W/PackageManager(14947): Failure retrieving icon 0x7f020004 in package com.a.project
W/PackageManager(14947): java.lang.NullPointerException
W/PackageManager(14947): at android.app.ActivityThread$ResourcesKey.<init>(ActivityThread.java:1138)
W/PackageManager(14947): at android.app.ActivityThread.getTopLevelResources(ActivityThread.java:1207)
W/PackageManager(14947): at android.app.ActivityThread.getTopLevelResources(ActivityThread.java:1266)
W/PackageManager(14947): at android.app.ContextImpl$ApplicationPackageManager.getResourcesForApplication(ContextImpl.java:2439)
W/PackageManager(14947): at android.app.ContextImpl$ApplicationPackageManager.getDrawable(ContextImpl.java:2332)
W/PackageManager(14947): at android.content.pm.PackageItemInfo.loadIcon(PackageItemInfo.java:140)
W/PackageManager(14947): at android.app.ContextImpl$ApplicationPackageManager.getApplicationIcon(ContextImpl.java:2387)
W/PackageManager(14947): at com.motorola.filemanager.utils.IconifiedText.buildIconItem(IconifiedText.java:287)
W/PackageManager(14947): at com.motorola.filemanager.local.DirectoryScanner.run(DirectoryScanner.java:83)
之后做一些研究,我发现下面的文章,导致没有具体的答案,这可能是问题的原因:
结果 HTTP://$c$c.google。 COM / p /安卓/问题/细节?ID = 9151
我确信设置以下权限清单文件:
I made sure to set the following permission in the Manifest file:
android.permission.WRITE_EXTERNAL_STORAGE
唯一的地方,在那里我访问软件包管理系统在我的code是retreival的versionName用途:
The only place, where I access the PackageManager in my code is for versionName retreival purposes:
try {
PackageManager manager = context.getPackageManager();
return manager.getPackageInfo(context.getPackageName(), 0).versionCode;
} catch (Exception e) {
e.printStackTrace();
}
没有任何人有什么线索可能会导致这个问题?
Does anybody have a clue what could cause this problem?
最好的问候,结果
米蒂亚
Best regards,
Mitja
推荐答案
空指针异常是
om.motorola.filemanager.utils.IconifiedText.buildIconItem(IconifiedText.java:287).
android.content.pm.PackageItemInfo.loadIcon(PackageItemInfo.java:140).
所以我猜你的项目在某处加载的apk文件的图标。之前 loadIcon
您应该添加以下两行:
pkg.applicationInfo.sourceDir = "apkpath"; //"apkpath" is your apk's absolute path
pkg.applicationInfo.publicSourceDir = "apkpath";
这篇关于检索失败在包图标的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!