function readOnly(count){ }
Starting November 20, the site will be set to read-only. On December 4, 2023,
forum discussions will move to the Trailblazer Community.
+ Start a Discussion
Bhola VishwakarmaBhola Vishwakarma 

error explanation

i am get the following error

 

System.ListException: List index out of bounds: 0

 

 public List<List<DataEntrySummaryBean>> getPresentFutureValueList {
        get {
            Integer listSize = summaryBeanIndexList.get(0).get(0).fieldList.size(), indexStart;
            for(List<DataEntrySummaryBean> summaryBeanList : summaryBeanIndexList) {                
                for(DataEntrySummaryBean summaryBean : summaryBeanList) {
                    indexStart = summaryBean.fieldList.size();
                    if(indexStart < listSize) {                 
                        for(Integer index = indexStart; index < listSize;index+=2) {
                            summaryBean.fieldList.add(0,0);
                           
                        }
                    }
                }   
            }            
            return summaryBeanIndexList;
        }           
    }  

 

 

Ankit AroraAnkit Arora

Lets suppose I have done this in my apex :

 

List<Account> acc = [select id from account where id =: 'r'] ;
System.debug('Id of Account :::: ' + acc[0].Id) ;

 

This will give me error "ListException: List index out of bounds: 0" as there is no record retrieved from query and am using the record Id. If the query is returning some value in any case then this error will not come.

 

Now there are many ways to resolve this one of them is listed below

 

List<Account> acc = [select id from account where id =: 'r'] ;
if(acc.size() > 0)
{
    System.debug('Id of Account :::: ' + acc[0].Id) ;
}

 

Please provide your code here if your problem is not resolved by this.

And if the problem gets resolved then mark it as solution :)

 

Thanks

Ankit Arora

Blog | Facebook | Blog Page

Bhola VishwakarmaBhola Vishwakarma

thanks ankit i have edited my code so can u help me an find out what should in do

Ankit AroraAnkit Arora

Please highlight the line where you are facing error, and if possible send the code which is calling this method.

 

Thanks

Ankit Arora

Blog | Facebook | Blog Page

Bhola VishwakarmaBhola Vishwakarma
 for(Integer currentYear = System.today().year(); currentYear < goalEndYear; currentYear++) {                    indexMap.put(currentYear,summaryBeanIndexList.size());            dataEntrySummaryBeanList = new List<DataEntrySummaryBean>();                        dataEntrySummaryBeanList.add((summaryBeanObj =new DataEntrySummaryBean()));                                                                                             summaryBeanIndexList.add(dataEntrySummaryBeanList);                                 sipBeanList.add(((sipBean = new SIPBean())));                                   goalSIPAmountList.add(new GoalSIPAmount__c(Goal__c=goalId,goal_year__c=currentYear,SIP_Debt__c =0,SIP_Equity__c=0,SIP_Gold__c=0,SIP_Outflow__c=true));                      goalPVActualSumMap.put(currentYear,0);            goalPVSIPCalculationList.add((sipBeanForPV = new SIPBean()));            summaryBeanObj.linkField = sipBean.financialYear = sipBeanForPV.financialYear = currentYear;                    }                           }

 

Ankit AroraAnkit Arora

I guess the problem is here :

 

for(Integer index = indexStart; index < listSize; index+=2)
{
    summaryBean.fieldList.add(0,0);
}

 If you are using "index" to get value from list then make sure it is not exceeding the total size of the list. Like this :

 

if(index <= Your_List.size())
{
}

 

Hope this will help.

 

Thanks

Ankit Arora

Blog | Facebook | Blog Page