You need to sign in to do that
Don't have an account?
babu Balagani
List index out of bounds: -69
Hi All,
By this code I am trying to do pagination.
list of records = 131.
when I am trying to click on (>>) button a nd imediately when I click on (<) button, it shown the error as: List index out of bounds: -69
please help me.
Thanks in advance
public List<wrapper> getInventories()
{
if(StIndex == 0)
{
fir = false;
last = true;
if (lstWrapper.size()==0){
start_record = 0;
total_records=0;
}
else start_record = 1;
total_records = lstWrapper.size();
If(lstWrapper.size()<totalNumberOfRecord)
{
end_record = lstWrapper.size();
last = false;
}
else
{
last = true;
end_record = totalNumberOfRecord;
}
}
else if(EndIndex == lstWrapper.size()-1)
{
fir = true;
last = false;
end_record =lstWrapper.size();
}
else
{
fir = true;
last = true;
}
if(StIndex != -1 && EndIndex != -1)
{
List<wrapper> lstW = new List<wrapper>();
if(EndIndex > lstWrapper.size()-1)
{
EndIndex = lstWrapper.size()-1;
}
for(integer i=StIndex;i<=EndIndex;i++)
{
lstW.add(lstWrapper[i]); >>>>>>>>>>>>>>>>>>>>>>>>>>>>> error
}
return lstW;
}
return lstWrapper;
}
public pagereference next()
{
if(EndIndex == lstWrapper.size()-1){
return null;
}
StIndex = EndIndex+1;
EndIndex = EndIndex + totalNumberOfRecord;
if(EndIndex > lstWrapper.size()-1){
EndIndex = lstWrapper.size()-1;
}
system.debug('StIndex-----'+StIndex);
system.debug('EndIndex -----'+EndIndex);
return null;
}
public pagereference previous()
{
if(StIndex == 0){
return null;
}
if(EndIndex < StIndex)
{
StIndex = lstWrapper.size() - totalNumberOfRecord;
}
EndIndex = StIndex-1;
StIndex = StIndex - totalNumberOfRecord;
system.debug('StIndex-----'+StIndex);
system.debug('EndIndex -----'+EndIndex);
return null;
}
public pagereference first()
{
if(StIndex == 0){
return null;
}
StIndex = 0;
if(EndIndex > lstWrapper.size()-1){
EndIndex = lstWrapper.size()-1;
}else{
EndIndex = totalNumberOfRecord-1;
}
system.debug('StIndex-----'+StIndex);
system.debug('EndIndex -----'+EndIndex);
return null;
}
public pagereference last()
{
if(EndIndex == lstWrapper.size()-1){
return null;
}
EndIndex = lstWrapper.size()-1;
StIndex = lstWrapper.size()-totalNumberOfRecord;
system.debug('StIndex-----'+StIndex);
system.debug('EndIndex -----'+EndIndex);
return null;
}
By this code I am trying to do pagination.
list of records = 131.
when I am trying to click on (>>) button a nd imediately when I click on (<) button, it shown the error as: List index out of bounds: -69
please help me.
Thanks in advance
public List<wrapper> getInventories()
{
if(StIndex == 0)
{
fir = false;
last = true;
if (lstWrapper.size()==0){
start_record = 0;
total_records=0;
}
else start_record = 1;
total_records = lstWrapper.size();
If(lstWrapper.size()<totalNumberOfRecord)
{
end_record = lstWrapper.size();
last = false;
}
else
{
last = true;
end_record = totalNumberOfRecord;
}
}
else if(EndIndex == lstWrapper.size()-1)
{
fir = true;
last = false;
end_record =lstWrapper.size();
}
else
{
fir = true;
last = true;
}
if(StIndex != -1 && EndIndex != -1)
{
List<wrapper> lstW = new List<wrapper>();
if(EndIndex > lstWrapper.size()-1)
{
EndIndex = lstWrapper.size()-1;
}
for(integer i=StIndex;i<=EndIndex;i++)
{
lstW.add(lstWrapper[i]); >>>>>>>>>>>>>>>>>>>>>>>>>>>>> error
}
return lstW;
}
return lstWrapper;
}
public pagereference next()
{
if(EndIndex == lstWrapper.size()-1){
return null;
}
StIndex = EndIndex+1;
EndIndex = EndIndex + totalNumberOfRecord;
if(EndIndex > lstWrapper.size()-1){
EndIndex = lstWrapper.size()-1;
}
system.debug('StIndex-----'+StIndex);
system.debug('EndIndex -----'+EndIndex);
return null;
}
public pagereference previous()
{
if(StIndex == 0){
return null;
}
if(EndIndex < StIndex)
{
StIndex = lstWrapper.size() - totalNumberOfRecord;
}
EndIndex = StIndex-1;
StIndex = StIndex - totalNumberOfRecord;
system.debug('StIndex-----'+StIndex);
system.debug('EndIndex -----'+EndIndex);
return null;
}
public pagereference first()
{
if(StIndex == 0){
return null;
}
StIndex = 0;
if(EndIndex > lstWrapper.size()-1){
EndIndex = lstWrapper.size()-1;
}else{
EndIndex = totalNumberOfRecord-1;
}
system.debug('StIndex-----'+StIndex);
system.debug('EndIndex -----'+EndIndex);
return null;
}
public pagereference last()
{
if(EndIndex == lstWrapper.size()-1){
return null;
}
EndIndex = lstWrapper.size()-1;
StIndex = lstWrapper.size()-totalNumberOfRecord;
system.debug('StIndex-----'+StIndex);
system.debug('EndIndex -----'+EndIndex);
return null;
}
I have modified the code , Please check, I hope you will not get this error now.