리스트와 배열 사이의 관계는 무엇입니까? 왜 ArrayIndexOutOfBoundsException가 발생합니까? Arraylist와 ArrayIndexOutOfBoundsException 사이의 관계
기본적 나 그 사용 HQL에 기초하는 방법에 하나 개의 인자를 통과하고 난 ArrayList를 한 세트를 반환하고있다. 이제 제 문제가 있습니다. 이 ArrayList 0 (size) 이상을 반환 할 때이 정확히 원하는 방식으로 작동합니다.하지만 0 (크기) ArrayList를 반환하면 예외가 발생합니다. 왜 그런가? 어떤 몸이 나에게 설명 할 수
지금 내가 ArrayList에 5가 (처음) & 0 내가 어떤 예외를 받고 있지 않다 (제 2의 사이즈로 난까지 테스트)를 돌려주는 경우처럼 한 번 더 의심을 얻었다. 하지만 그것은 200 개 이상의 요소를 반환 할 때 예외가 발생합니다. 그게 왜? 특정 상수 번호가 있습니까? 이 많은 요소 배열까지는 IndexOutofBounds와 같은 것을주지 말아야합니다.? 어떤 몸이라도 나에게 설명 할 수 있니?
public void setUpDisplay()
{
if (_flatView || _expired || _issue){ // these are all my views.
_deptBalances = fetchBalances(null);
}
else if (_searchGen.getGenericName() != null){
_storeGenList.clear();
_deptBalances = fetchBalances(_searchGen.getGenericName());
if (!ListUtil.nullOrEmptyList(_deptBalances)){
// i am displaying the result here.
}
else {
displaying error message.
}
}
// here i am using my _deptBalances to display(i am just putting this list into displaygroup).
}
// 여기에 내 방법 :
여기 내 코드입니다.
public List<DEPTStoreBalance> fetchBalances(String genName){
EntityManager em // Creating instance to entity manager.
List <DEPTStoreBalance> tempList = ListUtil.list();
String expClause = new String();
if (_expired){
expClause = "and gg.bSubjectToExpiration=true " +
"and msb.expirationDate <= :expDate ";
if(_expiringOnly){
expClause = expClause.concat(" and msb.expirationDate > :today");
}
else {
expClause = expClause +
"and (msb.expirationDate > :today " +
"or (balance.qtyBalance > 0 or balance.qtyInTransit > 0)) ";
}
}
else {
expClause = "and ((gg.bSubjectToExpiration=true " +
"and msb.expirationDate > :expDate) " +
"or gg.bSubjectToExpiration=false) ";
if (_flatView || _issue){
expClause = expClause.concat("and (balance.qtyBalance > 0 or balance.qtyInTransit > 0) ");
}
else if (genName != null){
expClause = expClause.concat("and gg.genericName = :genName ");
}
}
String hql = "select balance from DEPTStoreBalance as balance " +
" "+ // here are my joins with multiple tables.
"where dsg.store = :store " +
expClause;
if (_issue)
hql = hql.concat(" and dsi.deptIssue = :deptIssue");
Query q = em.createQuery(hql);
q.setParameter("store", _store); // here i am selecting the store(which is being changing in search component).
if (_issue)//Only saleable items should be issued
q.setParameter("expDate",12 months);
else
q.setParameter("expDate",_minExpDate); // constant value :3
if (_expired)
q.setParameter("today", new Date());
if (genName != null){
q.setParameter("genName", genName);
}
if (_issue)
q.setParameter("deptIssue", true);
try{
tempList = (List <DEPTStoreBalance>) q.getResultList();
}
catch (NoResultException nre){
//do something
}
finally {
em.close();
}
return tempList;
}
오류를 생성하는 코드를 게시 할 수 있습니까? – Keppil
아무도 나에게이 질문을 설명 할 수 있습니까? –
내가 언급 한대로 하나의 배열 목록을 반환합니다. 배열 목록에서 배열을 지우지 않고 처음으로 5 개의 요소를 반환하고 다음에 0 개의 요소를 반환하면 예외가 발생하지 않습니다.
그러나 배열 목록에서 다음 번에 200 번째 요소와 첫 번째 요소와 같은 요소가 더 많이 반환되면 예외가 발생합니다.
처음 두 번째로 의미하는 것은 검색 구성 요소에 배열을 사용하고 있음을 의미합니다. 배열 목록을 지우지 않고 항목을 검색하면 예외가 발생합니다.
왜 그런가요? 그게 내 질문이야. – Pesula