【发布时间】:2015-12-30 02:00:21
【问题描述】:
我可以这样做吗:
try {
loadItem();
} catch (NullPointerException e) {
Toast.makeText(getActivity(),"Sorry, we couldn't load that item. Please try again",Toast.LENGTH_SHORT).show();
}
并捕获可能在 loadItem() 中发生的任何 NullPointerExceptions?
【问题讨论】:
-
是的,你可以这样做。为什么不通过在该方法中抛出
NullPointerException来自己测试呢? -
你可以在问这里之前尝试一下
标签: android nullpointerexception try-catch