invoice_body
of invoice_data
is still null
, given this example. You can't just declare a thing as of type array and then use it, you still need to initialise it, so you can't access by index something that is nothing, let alone has no length.
To do this:
Invoice.invoice_body = new Invoice_Body_Item[desiredLength];
Where desiredLength
should be decided based on how much you're going to put in there/how many items you want or will end up with in the array. This should generally be calculable from the same data used to determine how many times to loop.