Populating a multi dimensional stuct

I’m having trouble populating a multi dimensional struct from a custom step in EI 4.6. I have a delimited list of account numbers as input. The custom step uses a simple StringTokenizer to parse each account number. When I try to populate out.accts[i].acct_num, I get the runtime error of ArrayIndexOutOfBoundsException. Any suggestions out there on how to populate my out multi dimensional struct?


Can you post a snippet of your code? At least the loop and maybe the allocation statement. From that we might see what is amiss.

Here is a snippet. Lets assume this step parsed an input string of 3 numbers. Instead of showing the parsing of the string, I just hard coded the values

customStepMethod$out out = new customStepMethod$out();

out.mRefs[0].mref_num = “100”;
out.mRefs[1].mref_num = “200”;
out.mRefs[2].mref_num = “300”;
return out;

public static class customStepMethod$out { 
    public mRefs[] mRefs = new mRefs[0]; 
    public static class mRefs { 
        public String mref_num; 

I get the ArrayIndexOutOf bounds error…even on the first assignment of mRef[0].mref_num.

public mRefs mRefs = new mRefs[0]; is the culprit.

The code is allocating an array with 0 entries. This is a fun side-effect of the code that is automatically generated by EI–it doesn’t know how many to allocate nor what var to use to set the size. You need to do it yourself by hand.

Assuming you’ll have 3 elements every time, you can use this instead:

public mRefs mRefs = new mRefs[3];

If the size needs to be dynamic, you can allocate the array right before you do the assignments:

out.mRefs = new out.mRefs[somevar];
out.mRefs[0].mref_num = “100”;
out.mRefs[1].mref_num = “200”;
out.mRefs[2].mref_num = “300”;


I thought it would be something like that but when I tried public mRefs mRefs = new mRefs[3]

EI over wrote it. (and it will be dynamic)

I tried the second option and had to fully qualify the mRefs. Here is the resulting code:

out.mRefs = new customStepMethod$out.mRefs[3];
out.mRefs[0].mref_num = “100”;
out.mRefs[1].mref_num = “200”;
out.mRefs[2].mref_num = “300”;

I get the dreaded null pointer exception when I run this.
out.mRefs[0].mref_num = “100” is the culprit.

try this…
Take a temporary array in the custom step and populate all ur values in to it, and then assign the temp. array to out.mRefs

This is at least the second time this subtle thing has caught me.

When allocating the array, the code is allocating slots for the entries to be placed there, but does not allocate the objects themselves. So the code:

out.mRefs = new customStepMethod$out.mRefs[3];

doesn’t give 3 mRefs objects, it gives an array with 3 slots for mRefs objects. What makes things more confusing is the fact that common string arrays imply that objects are allocated:

String list[] = new String[4]; 
list[0] = "abc"; 
list[1] = "def";

works but in fact we’ve actually instantiated 2 new String objects and placed references for them within the array slots. So we must do the same for any other object. This code should do the trick:

out.mRefs = new customStepMethod$out.mRefs[3]; 
for(int i=0; i<out.mRefs.length; i++) 
    out.mRefs = new customStepMethod$out.mRefs(); 
out.mRefs[0].mref_num = "100"; 
out.mRefs[1].mref_num = "200"; 
out.mRefs[2].mref_num = "300";