ArtistGui
ArtistGui copied to clipboard
Crash: Resources.NotFoundException in AppIconCache
https://github.com/Project-ARTist/ArtistGui/blob/efa7d3d5d2850940119dcebc94a786bad7af8b66/app/src/main/java/saarland/cispa/artist/artistgui/packagelist/view/AppIconCache.java#L55 getDrawableForDensity might throw a Resources.NotFoundException which causes the App to crash.
Since appIcon already can be null, just catch this Exception too. Might be nicer to return the default-Icon.
Yeah you're right! Thank you for reporting this. :)
I looked into this. The method getDrawableForDensity() throws a Resources.NotFoundException when the given id does not exist or is invalid (id=0). This won't happen because we get the app icon id from the PackageManager and fall back to the default android icon (android.R.mipmap.sym_def_app_icon) when the app doesn't have an icon.
getDrawableForDensity() - Throws NotFoundException if the given ID does not exist.: (https://developer.android.com/reference/android/content/res/Resources.html#getDrawableForDensity(int, int, android.content.res.Resources.Theme))
Default android icon fallback code: https://github.com/Project-ARTist/ArtistGui/blob/b4446410b0054f86bbc30d45f750cebb02e00262/app/src/main/java/saarland/cispa/artist/artistgui/applist/loader/AppListLoader.java#L118-L119
How is the state on this one? Is this resolved?
It is not resolved. A Resources.NotFoundException is thrown on my phone. Can be fixed by catching the exception and returning a default icon.
try {
Context mdpiContext = mContext.createPackageContext(packageEntry.packageName,
Context.CONTEXT_IGNORE_SECURITY);
appIcon = mdpiContext.getResources().getDrawableForDensity(packageEntry.appIconId,
DisplayMetrics.DENSITY_XHIGH, null);
put(packageEntry, appIcon);
} catch (PackageManager.NameNotFoundException e) {
e.printStackTrace();
} catch (Resources.NotFoundException e) {
return mContext.getDrawable(android.R.mipmap.sym_def_app_icon);
}
Could you provide a stack trace, please? (adb logcat)
Don't worry I think I know what the problem is. We load all our icons with mdpiContext. Even if there is no app icon we try to load the default icon with the same context object. Low resolution devices don't have the needed resources.
This is still a problem. My ArtistGui crashes while scrolling through the app list:
08-16 21:30:57.964 14469 14469 E AndroidRuntime: FATAL EXCEPTION: main
08-16 21:30:57.964 14469 14469 E AndroidRuntime: Process: saarland.cispa.artist.artistgui, PID: 14469
08-16 21:30:57.964 14469 14469 E AndroidRuntime: android.content.res.Resources$NotFoundException: Drawable com.koushikdutta.vysor:mipmap/ic_launcher with resource ID #0x7f0a0000
08-16 21:30:57.964 14469 14469 E AndroidRuntime: Caused by: android.content.res.Resources$NotFoundException: File res/mipmap-anydpi-v21/ic_launcher.xml from drawable resource ID #0x7f0a0000
08-16 21:30:57.964 14469 14469 E AndroidRuntime: at android.content.res.ResourcesImpl.loadDrawableForCookie(ResourcesImpl.java:725)
08-16 21:30:57.964 14469 14469 E AndroidRuntime: at android.content.res.ResourcesImpl.loadDrawable(ResourcesImpl.java:571)
08-16 21:30:57.964 14469 14469 E AndroidRuntime: at android.content.res.Resources.getDrawableForDensity(Resources.java:849)
08-16 21:30:57.964 14469 14469 E AndroidRuntime: at saarland.cispa.artist.artistgui.applist.adapter.AppIconCache.create(AppIconCache.java:55)
08-16 21:30:57.964 14469 14469 E AndroidRuntime: at saarland.cispa.artist.artistgui.applist.adapter.AppIconCache.create(AppIconCache.java:30)
08-16 21:30:57.964 14469 14469 E AndroidRuntime: at android.util.LruCache.get(LruCache.java:132)
08-16 21:30:57.964 14469 14469 E AndroidRuntime: at saarland.cispa.artist.artistgui.applist.adapter.AppListAdapter.onBindViewHolder(AppListAdapter.java:82)
08-16 21:30:57.964 14469 14469 E AndroidRuntime: at saarland.cispa.artist.artistgui.applist.adapter.AppListAdapter.onBindViewHolder(AppListAdapter.java:37)
08-16 21:30:57.964 14469 14469 E AndroidRuntime: at android.support.v7.widget.RecyclerView$Adapter.onBindViewHolder(RecyclerView.java:6482)
08-16 21:30:57.964 14469 14469 E AndroidRuntime: at android.support.v7.widget.RecyclerView$Adapter.bindViewHolder(RecyclerView.java:6515)
08-16 21:30:57.964 14469 14469 E AndroidRuntime: at android.support.v7.widget.RecyclerView$Recycler.tryBindViewHolderByDeadline(RecyclerView.java:5458)
08-16 21:30:57.964 14469 14469 E AndroidRuntime: at android.support.v7.widget.RecyclerView$Recycler.tryGetViewHolderForPositionByDeadline(RecyclerView.java:5724)
08-16 21:30:57.964 14469 14469 E AndroidRuntime: at android.support.v7.widget.RecyclerView$Recycler.getViewForPosition(RecyclerView.java:5563)
08-16 21:30:57.964 14469 14469 E AndroidRuntime: at android.support.v7.widget.RecyclerView$Recycler.getViewForPosition(RecyclerView.java:5559)
08-16 21:30:57.964 14469 14469 E AndroidRuntime: at android.support.v7.widget.LinearLayoutManager$LayoutState.next(LinearLayoutManager.java:2229)
08-16 21:30:57.964 14469 14469 E AndroidRuntime: at android.support.v7.widget.LinearLayoutManager.layoutChunk(LinearLayoutManager.java:1556)
08-16 21:30:57.964 14469 14469 E AndroidRuntime: at android.support.v7.widget.LinearLayoutManager.fill(LinearLayoutManager.java:1516)
08-16 21:30:57.964 14469 14469 E AndroidRuntime: at android.support.v7.widget.LinearLayoutManager.scrollBy(LinearLayoutManager.java:1330)
08-16 21:30:57.964 14469 14469 E AndroidRuntime: at android.support.v7.widget.LinearLayoutManager.scrollVerticallyBy(LinearLayoutManager.java:1074)
08-16 21:30:57.964 14469 14469 E AndroidRuntime: at android.support.v7.widget.RecyclerView$ViewFlinger.run(RecyclerView.java:4838)
08-16 21:30:57.964 14469 14469 E AndroidRuntime: at android.view.Choreographer$CallbackRecord.run(Choreographer.java:874)
08-16 21:30:57.964 14469 14469 E AndroidRuntime: at android.view.Choreographer.doCallbacks(Choreographer.java:686)
08-16 21:30:57.964 14469 14469 E AndroidRuntime: at android.view.Choreographer.doFrame(Choreographer.java:618)
08-16 21:30:57.964 14469 14469 E AndroidRuntime: at android.view.Choreographer$FrameDisplayEventReceiver.run(Choreographer.java:860)
08-16 21:30:57.964 14469 14469 E AndroidRuntime: at android.os.Handler.handleCallback(Handler.java:751)
08-16 21:30:57.964 14469 14469 E AndroidRuntime: at android.os.Handler.dispatchMessage(Handler.java:95)
08-16 21:30:57.964 14469 14469 E AndroidRuntime: at android.os.Looper.loop(Looper.java:154)
08-16 21:30:57.964 14469 14469 E AndroidRuntime: at android.app.ActivityThread.main(ActivityThread.java:6186)
08-16 21:30:57.964 14469 14469 E AndroidRuntime: at java.lang.reflect.Method.invoke(Native Method)
08-16 21:30:57.964 14469 14469 E AndroidRuntime: at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:889)
08-16 21:30:57.964 14469 14469 E AndroidRuntime: at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:779)
08-16 21:30:57.964 14469 14469 E AndroidRuntime: Caused by: android.view.InflateException: Class not found adaptive-icon
08-16 21:30:57.964 14469 14469 E AndroidRuntime: at android.graphics.drawable.DrawableInflater.inflateFromClass(DrawableInflater.java:206)
08-16 21:30:57.964 14469 14469 E AndroidRuntime: at android.graphics.drawable.DrawableInflater.inflateFromXml(DrawableInflater.java:128)
08-16 21:30:57.964 14469 14469 E AndroidRuntime: at android.graphics.drawable.Drawable.createFromXmlInner(Drawable.java:1227)
08-16 21:30:57.964 14469 14469 E AndroidRuntime: at android.graphics.drawable.Drawable.createFromXml(Drawable.java:1200)
08-16 21:30:57.964 14469 14469 E AndroidRuntime: at android.content.res.ResourcesImpl.loadDrawableForCookie(ResourcesImpl.java:715)
08-16 21:30:57.964 14469 14469 E AndroidRuntime: ... 30 more
08-16 21:30:57.964 14469 14469 E AndroidRuntime: Caused by: java.lang.ClassNotFoundException: Didn't find class "adaptive-icon" on path: DexPathList[[],nativeLibraryDirectories=[/system/app/EasterEgg/lib/arm, /system/lib, /vendor/lib, /system/lib, /vendor/lib]]
08-16 21:30:57.964 14469 14469 E AndroidRuntime: at dalvik.system.BaseDexClassLoader.findClass(BaseDexClassLoader.java:56)
08-16 21:30:57.964 14469 14469 E AndroidRuntime: at java.lang.ClassLoader.loadClass(ClassLoader.java:380)
08-16 21:30:57.964 14469 14469 E AndroidRuntime: at java.lang.ClassLoader.loadClass(ClassLoader.java:312)
08-16 21:30:57.964 14469 14469 E AndroidRuntime: at android.graphics.drawable.DrawableInflater.inflateFromClass(DrawableInflater.java:187)
08-16 21:30:57.964 14469 14469 E AndroidRuntime: ... 34 more
The fix suggested by @alexcekay solves this issue for me.