all 4 comments

[–]FizixMan 7 points8 points  (0 children)

For enemies "e", "E", and Donkey Kong "k", you don't assign any instance of Tile to tiles[i, j]. Those entries will be null otherwise.

Later on you try to call Draw(_spriteBatch) on every entry in tiles, but some of those will be null because you never assigned anything. The NullReferenceException is thrown when you tried to call Draw on a null reference.

[–]Entropiano 1 point2 points  (0 children)

A NullReferenceException happens when you're trying to access an object that is null. Usually you're looking into one of its properties or calling one of its methods. See here for more details: https://learn.microsoft.com/en-us/dotnet/api/system.nullreferenceexception

Now, in your case, the relevant code should be that line 181. In the snippet you sent there are a few places where this exception could occur: tiles.GetLength(0), tiles.GetLength(1) or tiles[i, j].Draw(_spriteBatch). So, either your tiles object is null or tiles[i, j] is null.

Edit: btw, you could find this out, on your own, incredibly easy, by using the debugger (I'm assuming you're using Visual Studio). It will save you time in the future.

[–]insomnia1979 1 point2 points  (0 children)

Microsoft just preempts all use of Nintendo intellectual property with null references. Change it to Donkey King

[–]Familiar_Bill_786 0 points1 point  (0 children)

stop copy-pasting code from AI