Skip to content

Commit

Permalink
Catch NotFoundException from getDrawable()
Browse files Browse the repository at this point in the history
And return `null` in that case. Keeps the app from crashing.
  • Loading branch information
markusfisch committed May 18, 2024
1 parent c3331ca commit 888f1fe
Showing 1 changed file with 6 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
import android.content.pm.PackageManager;
import android.content.pm.ResolveInfo;
import android.content.res.Resources;
import android.content.res.Resources.NotFoundException;
import android.graphics.drawable.Drawable;
import android.os.Build;
import android.util.Xml;
Expand Down Expand Up @@ -46,7 +47,11 @@ public Drawable getDrawable(String drawableName) {
@SuppressLint("DiscouragedApi")
int id = resources.getIdentifier(drawableName, "drawable",
packageName);
return id > 0 ? resources.getDrawable(id) : null;
try {
return id > 0 ? resources.getDrawable(id) : null;
} catch (NotFoundException e) {
return null;
}
}

public ArrayList<String> getDrawableNames() {
Expand Down

0 comments on commit 888f1fe

Please sign in to comment.