cancel
Showing results for 
Search instead for 
Did you mean: 

regarding Exceptionjava.lang.IndexOutOfBoundsException: Index: 0, Size: 0

Former Member
0 Kudos

hi everyone

I am getting the following error:Exceptionjava.lang.IndexOutOfBoundsException: Index: 0, Size: 0

in the following code can someone pls advice me the reason for this error

for(int index=0; index<=wdContext.currentSerachMaterialListElement().nodeCompoItems().size(); index++)

{

wdThis.wdGetAPI().getMessageManager().reportSuccess("index"+index);

double partWeights = Math.floor(wdContext.currentSerachMaterialListElement().nodeCompoItems().getCompoItemsElementAt(index).getKwmeng().multiply(wdContext.currentSerachMaterialListElement().nodeCompoItems().getCompoItemsElementAt(index).getBrgew()).doubleValue());

wdContext.currentSerachMaterialListElement().nodeCompoItems().getCompoItemsElementAt(index).currentVnBOM_DetailsElement().setVaWeight(partWeights);

grossWeightParts +=partWeights;

double noOfPallets = wdContext.currentSerachMaterialListElement().nodeCompoItems().getCompoItemsElementAt(index).getKwmeng().divide(new BigDecimal(wdContext.currentSerachMaterialListElement().nodeCompoItems().getCompoItemsElementAt(index).getMaxqty()),0).doubleValue();

wdContext.currentSerachMaterialListElement().nodeCompoItems().getCompoItemsElementAt(index).currentVnBOM_DetailsElement().setVaNoOfPallets(noOfPallets);

totalPalletsRequired += noOfPallets;

palletsGrossWeight += Math.floor(new BigDecimal(String.valueOf(noOfPallets)).multiply(wdContext.currentSerachMaterialListElement().nodeCompoItems().getCompoItemsElementAt(index).getBrgew_P()).doubleValue());

}

wdThis.wdGetAPI().getMessageManager().reportSuccess("aftr 2nd for loop");

totalGrossWeight = grossWeightParts + palletsGrossWeight;

wdContext.currentSerachMaterialListElement().nodeVnTruckNode().currentVnTruckNodeElement().setVaGrossWeight(grossWeightParts);

wdContext.currentSerachMaterialListElement().nodeVnTruckNode().currentVnTruckNodeElement().setVaPalletsGrossWeight(palletsGrossWeight);

wdContext.currentSerachMaterialListElement().nodeVnTruckNode().currentVnTruckNodeElement().setVaTotalGrossWeight(totalGrossWeight);

wdContext.currentSerachMaterialListElement().nodeVnTruckNode().currentVnTruckNodeElement().setVaTotalPallets(totalPalletsRequired);

my first report success in which index value is cummin 0 n size of node is also 0

but its not cummin out of the for loop its giving exception in the for loop

thanks & regards

jaspreet

Accepted Solutions (1)

Accepted Solutions (1)

Former Member
0 Kudos

Hi

Since in the for loop you are checking for index<=..... its throwing this exception.

Please change it to index<......

Regards

Akshaya

Former Member
0 Kudos

yeah thanks akshaya...it worked..

Answers (3)

Answers (3)

Former Member
0 Kudos

try this

for(int index=0; index<wdContext.currentSerachMaterialListElement().nodeCompoItems().size(); index++)

Former Member
0 Kudos

Hi Jaspreet,

Loop over this and try,

<b>for(int index=0; index<=wdContext.nodeCompoItems().size(); index++)</b>

Regards,

Murtuza

Former Member
0 Kudos

Hi Jaspreet,

Please check whether node <b>wdContext.currentSerachMaterialListElement().nodeCompoItems().</b> has elements in that or is empty before trying to access its elements. There is an API method available.

Regards,

Ganga.