I got it when trying to initialize my array of sprites
(( the only one trowing me null is the sprite2D[] AllianceCharacters


declaration:

sprite2D[] AllianceCharacters;
static string Cardspath = Directory.GetCurrentDirectory() + "\\Content\\Cards";
string[] ActionBar = Directory.GetFiles(Cardspath + "\\ActionBar\\");
        string[] Equips = Directory.GetFiles(Cardspath + "\\ActionBar\\Equips");
        string[] CharactersAlliance = Directory.GetFiles(Cardspath + "\\Characters\\Alliance\\");
        string[] CharactersHorde = Directory.GetFiles(Cardspath + "\\Characters\\Horde\\");
        string[] CharactersMonster = Directory.GetFiles(Cardspath + "\\Characters\\Monster\\");

initialization:

for (int i = 0; i < CharactersAlliance.Length; i++)
            {

                AllianceCharacters[i] = new sprite2D(Content.Load<Texture2D>(Cardspath + "\\Characters\\Alliance\\" + CharactersAlliance[i]));
                AllianceCharacters[i].name = CharactersAlliance[i];

            }

//This is called at the beginning::

void FixNames()
        {
            int x, y, z, a, h, m;
            
            y = Equips.Length;
            z = ActionBar.Length;
            a = CharactersAlliance.Length;
            h = CharactersHorde.Length;
            m = CharactersMonster.Length;
            
            char[] xnb = { 'b', 'n', 'x', '.' };

            for (x = 0; x < y; x++)
            {
                Equips[x] = Path.GetFileName(Equips[x]);
                Equips[x] = Equips[x].TrimEnd(xnb);
            }
            for (x = 0; x < z; x++)
            {
                ActionBar[x] = Path.GetFileName(ActionBar[x]);
                ActionBar[x] = ActionBar[x].TrimEnd(xnb);
            }
            for (x = 0; x < a; x++)
            {
                CharactersAlliance[x] = Path.GetFileName(CharactersAlliance[x]);
                CharactersAlliance[x] = CharactersAlliance[x].TrimEnd(xnb);
            }
            for (x = 0; x < h; x++)
            {
                CharactersHorde[x] = Path.GetFileName(CharactersHorde[x]);
                CharactersHorde[x] = CharactersHorde[x].TrimEnd(xnb);
            }
            for (x = 0; x < m; x++)
            {
                CharactersMonster[x] = Path.GetFileName(CharactersMonster[x]);
                CharactersMonster[x] = CharactersMonster[x].TrimEnd(xnb);
            }
        }

any idea on what could be making it fail ?

solved::

added and modified

static int NumberAllianceCharacter = Directory.GetFiles(Cardspath + "\\Characters\\Alliance\\").Length;
 CharacterCards [] ACharacters = new CharacterCards[NumberAllianceCharacter];

how is the size of AllianceCharacters[] determined? You probably need a "new" statement to instantiate the entire array (in addition to its members, which you have done in your method)

Yup as jonsca said, you haven't initialized the array. Either do:

sprite2D[] AllianceCharacters = new sprite2D[2]; // hold 2 sprite2D objects

Or use a List<T>:

List<sprite2D> AllianceCharacters = new List<sprite2D>;

Edited 7 Years Ago by Ravenheart: put code in [code]

This question has already been answered. Start a new discussion instead.