Search code examples
axaptaaxdynamics-ax-2012

Object not initialized error when looping over a List in Dynamics AX?


The Problem:

  • I have a list with Objects as elements.
  • I use enumerator to loop over the list.
  • While looping I assign elements to a variable object with the same type as the element.
  • When I call a method on the object, but I get the following error-message:

MyClass object not initialized.

I think I must cast, but don't know how to do this in Dynamics AX.

I develop in MS Dynamics AX 2012.

MyExampleDataContract exampleDataContract = new MyExampleDataContract();
while (listEnumerator.moveNext())
{
    exampleDataContract = listEnumerator.current();
    info(exampleDataContract.parmCustomerId()); //This gives an error.
}

Solution

  • A list element can be null.

    List l = new List(Types::Class);
    ;
    l.addEnd(null);
    info(int2str(l.elements()));