【发布时间】:2012-03-26 19:19:42
【问题描述】:
我正在尝试将对象添加到 ArrayList 并抛出 ArrayIndexOutOfBoundsException 以下是代码
private void populateInboxResultHolder(List inboxErrors){
inboxList = new ArrayList();
try{
inboxHolder = new InboxResultHolder();
//Lots of Code
inboxList.add(inboxHolder);
}catch(Exception e){
e.printStackTrace();
}
}
例外是
[3/7/12 15:41:26:715 UTC] 00000045 SystemErr R java.lang.ArrayIndexOutOfBoundsException
[3/7/12 15:41:26:721 UTC] 00000045 SystemErr R at java.util.ArrayList.add(ArrayList.java:378)
[3/7/12 15:41:26:721 UTC] 00000045 SystemErr R at com.ml.fusion.ui.common.web.bean.inbox.InboxSearchBean.populateInboxResultHolder(InboxSearchBean.java:388)
[3/7/12 15:41:26:721 UTC] 00000045 SystemErr R at com.ml.fusion.ui.common.web.bean.inbox.InboxSearchBean.searchInboxErrors(InboxSearchBean.java:197)
[3/7/12 15:41:26:721 UTC] 00000045 SystemErr R at com.ml.fusion.ui.common.web.bean.inbox.InboxSearchBean.viewInbox(InboxSearchBean.java:207)
但是根据 ArrayList.add 的签名,它不应该抛出这个异常。 请帮忙。
【问题讨论】:
-
好吧,既然 IndexOutOfBoundsException 是一个 RuntimeException,它可以在方法签名中不提及。
-
ArrayIndexOutOfBoundsException是运行时异常,而不是检查异常,因此它不一定会出现在抛出它的方法的签名中。 -
没错。但是如果您查看 add 方法本身,则不可能抛出此异常
标签: java indexoutofboundsexception