Reputation: 4708
I have been troubled by this for a while now, this is the code I have:
TILArray = new string[Width, Height];
int t = 0;
TILArray[t, t] = "";
TILArray[t, t] = "";
for (int x = 0; x < Width; x++)
{
for (int y = 0; y < Height; y++)
{
if (TILList[x][y] != null)
{
TILArray[0, 0] = TILList[x][y];
Tiles[x, y] = Content.Load<Tile>(TILList[x][y]);
}// This line throws the excetion
}
}
The line that throws the exception is actually the right curly brace marked above.
An unhandled exception of type 'System.NullReferenceException' occurred in TileEngine.dll
Additional information: Object reference not set to an instance of an object.
Upvotes: 0
Views: 182
Reputation: 4708
I needed to reinitialize the Tiles array when I set the width and height That fixed it
Upvotes: 0
Reputation: 32418
My guess is that it's Content
that is null and you're calling the method before the game's LoadContent
method is called, or before you set up Content
.
Ensure you're setting the Content
member correctly. This should be done for you in the default game template. Also, ensure you're loading content after (or within) the game's LoadContent
method.
Upvotes: 2