-->
These old forums are deprecated now and set to read-only. We are waiting for you on our new forums!
More modern, Discourse-based and with GitHub/Google/Twitter authentication built-in.

All times are UTC - 5 hours [ DST ]



Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 4 posts ] 
Author Message
 Post subject: IndexOutOfBoundsException
PostPosted: Thu Aug 25, 2005 2:08 pm 
Newbie

Joined: Tue Aug 23, 2005 12:46 pm
Posts: 5
Hi All,

We recently upgraded to Hibernate 3.0 from 2.0. I am getting the following error message. My code worked fine in Hibernate 2.0.

java.lang.IndexOutOfBoundsException: Index: 17, Size: 16
at java.util.ArrayList.RangeCheck(Unknown Source)
at java.util.ArrayList.get(Unknown Source)


Here is the code that is causing the above error.

When the lastIndex is 19, then I am getting the above error.

int subHeaderIndex = 14;
int lastIndex = this.getComponentCount();
for (int ii = subHeaderIndex; ii < lastIndex; ii++) {
this.remove(ii);
}

Please help me if anybody knows anything about this.

Thank You,
Sirisha.


Top
 Profile  
 
 Post subject: different direction
PostPosted: Thu Aug 25, 2005 2:48 pm 
Expert
Expert

Joined: Fri Jul 22, 2005 2:42 pm
Posts: 670
Location: Seattle, WA
Well, I do not know how it was possible for that code to work, basically when you remove an element from array then its length decreases and last index is not initialLength-1 anymore,
so as you increase index you simply go out ot of boundaries.

you may change the algorithm to somethig like:


for( int i=0; i < length; i++){
arrayList.remove( subHeaderIndex );
}

or
lastIndex = this.getComponentCount() -1;
for( int i=lastIndex; i >= subHeaderIndex; i--){
arrayList.remove( i );
}

_________________
--------------
Konstantin

SourceLabs - dependable OpenSource systems


Top
 Profile  
 
 Post subject: IndexOutOfBoundsExcpetion
PostPosted: Thu Aug 25, 2005 4:49 pm 
Newbie

Joined: Tue Aug 23, 2005 12:46 pm
Posts: 5
Thank you for your reply. Sorry, I was not clear in my previous message.

I am not trying to remove an element from an array. I am trying to remove the component from the panel. For Ex: I had 19 components and I wanted to remove the 15th , 16th, 17th, 18th and 19th components from the panel.

Thank You,
Sirisha.


Top
 Profile  
 
 Post subject: index
PostPosted: Thu Aug 25, 2005 5:01 pm 
Expert
Expert

Joined: Fri Jul 22, 2005 2:42 pm
Posts: 670
Location: Seattle, WA
if you have 19 elements then last index is 18;
so use
int lastIndex = this.getComponentCount() -1;

_________________
--------------
Konstantin

SourceLabs - dependable OpenSource systems


Top
 Profile  
 
Display posts from previous:  Sort by  
Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 4 posts ] 

All times are UTC - 5 hours [ DST ]


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum

Search for:
© Copyright 2014, Red Hat Inc. All rights reserved. JBoss and Hibernate are registered trademarks and servicemarks of Red Hat, Inc.