returning arrays correctly

Hi, I’ve got a function in a class, which returns an araay of strings:
(into a weaponCards class)

public string[] getCards(){
        for (int i=0; i<5; i++) {
            cardList[i] =(CardContainer[i].cardName);
        }
        return cardList;
    }

and now I’d like to retrieve these array into another class, but I get a
NullReferenceException: Object reference not set to an instance of an object
(wrapper stelemref) object:stelemref (object,intptr,object)
.
I believed that I correctly initialize my array, but apparently not :

string[] values = new string[5];
values= weaponCards.getCards();
            }

Where have you initialized ‘cardList’ before adding into it? I think you are missing something like : cardList = new string[5];

it’s a public array, initialized in the unity editor,
If i print the values, it all work, it’s once I try to get the array from the other class that i get errors
in fact it’s not really
for(int i=0;i<5;i++)

it’s exactly
for (int i =0; i < cardList.Length;i++)

If you have initialised cardList then I’d look at CardContainer, as that could be null itself OR a value in that could be null and you are trying to access .cardName on a null value.