cancel
Showing results for 
Search instead for 
Did you mean: 

Avoid java.lang.IndexOutOfBoundsException error

Former Member
0 Kudos

This is the error message:


java.lang.IndexOutOfBoundsException: Index: 3, Size: 3 

    at at java.util.ArrayList.RangeCheck(ArrayList.java:539)
    at at java.util.ArrayList.get(ArrayList.java:356)

Below line of coding is the place where system encounter the error

node.setLeadSelection(j); //this is the place causing the error


             if (!"".equals(wdContext.getCurrentElement()
                 .getAttributeValue((String) contextInputFields.get(c))))
			 {
				 allFieldsEmpty = false;
			} else {
				wdThis.raiseNoAnswersMaintained();
			}
		}

		// if all answer fields are empty then set the question lead selection from 1...n
		if (allFieldsEmpty) {
			// set lead selection of dropdown listboxes from 1...n
			for (int j = 0; j < contextDropDowns.size(); j++) {
				IWDNode node =
					wdContext.getChildNode(
						(String) contextDropDowns.elementAt(j),
						0);
				node.setLeadSelection(j); //this is the place causing the error
			}
			for (int j = 0; j < contextDropDowns.size(); j++) {
				IWDNode node =
					wdContext.getChildNode(
						(String) contextDropDowns.elementAt(j) + "Overview",
						0);
				node.setLeadSelection(j);
			}

		}

What should i do to avoid this error?

There is quite similar thread reported, but no solution given in the thread.

Appreciate any comment/suggestion.

regards,

Prakesh.

Accepted Solutions (0)

Answers (2)

Answers (2)

gill367
Active Contributor
0 Kudos

Hi prakash,

I am not getting what you are trying to do for getting the Node.

Could you please explain what is

contextDropDowns

you should directly get the node using wdcontext.node<node name>.

I think the method that you are trying is not giving the correct node to you and so index is going out of range.

Reagrds,

Sarbjeet.

Abhinav_Sharma
Contributor
0 Kudos

hi Prakash

The error comes if the given index is not in within the node elements. You can try adding a condition to check the size of node.

Set the lead selection inside a condtion

if(node.size() >= j) {

node.setLeadSelection(j); //this is the place causing the error

}

As following statement returns a node and it is quite possible that the node elements are less than the size value j.

IWDNode node = wdContext.getChildNode((String) contextDropDowns.elementAt(j),0);

Lemme know if it helps

Abhinav