如何捕获android.content.res.Resources $ NotFoundException

zoo*_*ter 3 android exception

很抱歉,如果这是一个愚蠢的问题,但我如何在我的代码中捕获此特定异常?即,在我的Catch块中,catch关键字应该是什么?

Mik*_* M. 5

你可以用catch(Resources.NotFoundException e).在$您的堆栈跟踪只是意味着NotFoundException是一个嵌套类Resources.

您可以导入完全限定的类NotFoundException- 也就是说android.content.res.Resources.NotFoundException- 并且只是NotFoundException在中使用catch,但是可读性和理解力可以更好地包含这样一个通用命名的包含类Exception.