Below code is throwing an IndexOutOfBoundsException at line Field f = getField(counter);
Why is it being thrown ? Surely the field exists because I am looping based on fieldcount. Or is the list fields in the manager not gauranteed to be sequential? If this is the case how should I delete fields from a screen that are of type – MyButtonField
Thanks
int fieldCount = getFieldCount() - 1;
if(fieldCount > 1){
for(int counter = 0; counter <= fieldCount ; ++counter){
Field f = getField(counter);
if(f instanceof MyButtonField){
delete(f);
}
}
}
You haven’t specified what
delete(f)does, but if it removes it from the list of fields, then your “valid count” will effectively decrease.To rewrite this somewhat and fix the problem:
This will go from the end of the fields instead of the start, so it doesn’t matter if you remove an entry and everything shuffles up – the items which shuffle up will be the ones you’ve already looked at.