You need to sign in to do that
Don't have an account?
Sylvio Avilla
List index out of bounds: -1 (List is not empty!)
Hello everyone,
Bellow is part of a code and I would like to know if someone could tell me why I’m receiving the error "List index out of bounds: -1" for po.Interval2__c even though po.Size__c = 4 ( if I delete line po.Interval2__c =myValues[myValues.size()-2]; code runs ok )
Thanks
Sylvio
Bellow is part of a code and I would like to know if someone could tell me why I’m receiving the error "List index out of bounds: -1" for po.Interval2__c even though po.Size__c = 4 ( if I delete line po.Interval2__c =myValues[myValues.size()-2]; code runs ok )
List<Integer> myValues = new List<Integer>(); myValues.add(myValue); (myValues.sort()); po.Interval1__c = myValues[myValues.size()-1]; po.Interval2__c =myValues[myValues.size()-2]; po.Size__c = myValues.size();
Thanks
Sylvio
I see there is something wrong in this code.
If the list has only one element, you will get this error. PFB the step by step explanation.
Thanks
Brahma
All Answers
I see there is something wrong in this code.
If the list has only one element, you will get this error. PFB the step by step explanation.
Thanks
Brahma
I found the error. In my complete code, this function was inside a LOOP... so, the part :
Should be outside....
Thank you again