Reputation: 941
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)
After doing some research, I found the following article, leading to no concrete answer, what could be the cause of the problem:
http://code.google.com/p/android/issues/detail?id=9151
I made sure to set the following permission in the Manifest file:
android.permission.WRITE_EXTERNAL_STORAGE
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
Upvotes: 2
Views: 3889
Reputation: 1
before where u return .... add: PackageInfo packageInfo = getPackageManager(context).getPackageInfo( context.getPackageName(), 0); packageinfo.applicationInfo.sourceDir = mSavePath+"/"+APKNAME;//your apk absolute packageinfo.applicationInfo.publicSourceDir = mSavePath+"/"+APKNAME;//your apk absolute
Upvotes: 0
Reputation: 21
The null pointer exception is at
om.motorola.filemanager.utils.IconifiedText.buildIconItem(IconifiedText.java:287).
android.content.pm.PackageItemInfo.loadIcon(PackageItemInfo.java:140).
so I guess your project loaded the apk's icon in somewhere. Before loadIcon
you should be add the following two lines:
pkg.applicationInfo.sourceDir = "apkpath"; //"apkpath" is your apk's absolute path
pkg.applicationInfo.publicSourceDir = "apkpath";
Upvotes: 2