zooter
zooter

Reputation: 2208

How to catch android.content.res.Resources$NotFoundException

Sorry if this is a dumb question, but how do I catch this particular exception in my code? i.e, in my Catch block, what should be the catch keyword?

Upvotes: 5

Views: 2367

Answers (2)

Mike M.
Mike M.

Reputation: 39191

You can use catch(Resources.NotFoundException e). The $ in your stack trace just means NotFoundException is a nested class in Resources.

You could import the fully qualified class for NotFoundException - that is, android.content.res.Resources.NotFoundException - and just use NotFoundException in the catch, but it's arguably better for readability and comprehension to include the containing class for such a generically named Exception.

Upvotes: 9

Nirav Ranpara
Nirav Ranpara

Reputation: 13785

Use NotFoundException

 try {
                drawable = Resources.getSystem().getDrawable(R.drawable.icon);
            } catch (NotFoundException e) {
                e.printStackTrace();
            }

Upvotes: 0

Related Questions