mav*_*rav 16 java indexoutofboundsexception
我试图将一个对象添加到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();
}
}
Run Code Online (Sandbox Code Playgroud)
例外是
[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)
Run Code Online (Sandbox Code Playgroud)
但是根据ArrayList.add的签名,它不应该抛出这个异常.请帮忙.
Dav*_*ebb 30
ArrayList.add()永远不应该抛出一个ArrayIndexOutOfBoundsException"正确"的使用,所以你似乎ArrayList以一种它不支持的方式使用你.
很难从你发布的代码中分辨出来,但我的猜测是你ArrayList从多个线程访问你的代码.
ArrayList不同步,因此不是线程安全的.如果这是问题,您可以通过包装您的List使用来修复它Collections.synchronizedList().
| 归档时间: |
|
| 查看次数: |
12103 次 |
| 最近记录: |