简体   繁体   中英

Why does this line throw an exception?

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.

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.

当我设置固定它的宽度和高度时,我需要重新初始化Tiles数组

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM