Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Crash: Resources.NotFoundException in AppIconCache #26

Open
fYsh-de opened this issue Oct 26, 2017 · 7 comments · May be fixed by #87
Open

Crash: Resources.NotFoundException in AppIconCache #26

fYsh-de opened this issue Oct 26, 2017 · 7 comments · May be fixed by #87
Labels

Comments

@fYsh-de
Copy link

fYsh-de commented Oct 26, 2017

appIcon = mdpiContext.getResources().getDrawableForDensity(packageEntry.getAppIconId(),

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.

@fYsh-de fYsh-de changed the title Crash: Crash: Resources.NotFoundException in AppIconCache Oct 26, 2017
@partipan-dot
Copy link
Collaborator

Yeah you're right! Thank you for reporting this. :)

@partipan-dot
Copy link
Collaborator

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:

appIconId = applicationInfo.icon == 0 ?
android.R.mipmap.sym_def_app_icon : applicationInfo.icon;

@schrnz
Copy link
Member

schrnz commented Mar 25, 2018

How is the state on this one? Is this resolved?

@alexcekay
Copy link

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);
}

@partipan-dot
Copy link
Collaborator

Could you provide a stack trace, please? (adb logcat)

@partipan-dot partipan-dot reopened this Jun 26, 2018
@partipan-dot
Copy link
Collaborator

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.

@partipan-dot partipan-dot removed their assignment Aug 1, 2018
@alfink
Copy link
Collaborator

alfink commented Aug 16, 2018

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.

alfink added a commit to alfink/ArtistGui that referenced this issue Jan 4, 2019
(cherry picked from commit 5888ad5)
alfink added a commit to alfink/ArtistGui that referenced this issue Sep 12, 2019
(cherry picked from commit 5888ad5)

(cherry picked from commit f3830ab)
@alfink alfink linked a pull request Sep 12, 2019 that will close this issue
alfink added a commit to alfink/ArtistGui that referenced this issue Sep 12, 2019
(cherry picked from commit 5888ad5)

(cherry picked from commit f3830ab)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging a pull request may close this issue.

5 participants