Element 1 is undefined in a Java object of type class coldfusion.runtime.Array

This error is thrown when you try and access an element in an Array that is undefined. How would this happen? Here’s what I did.

I wanted to make an array of 2 elements. I did this in a loop that ran 5 times. Instead of making an array of 2 elements, I made an array of 5 elements, only 2 of which were defined:

Here is the messed up array:

messed up array

So check your array, and make sure when it is being created that no undefined elements are created by skipping element assignments. Mae sure you don’t create an array, and then do something like:

<cfset items[3]="bbgun" />
<cfset items[5]="bb" />

Here, elements 1,2, and 4 will be undefined. Should be:

<cfset items[1]="bbgun" />
<cfset items[2]="bb" />

Leave a Reply

Your email address will not be published. Required fields are marked *