-1

This is my first post here so please be gentle. This is my first time making a game in C# XNA (I know it's not supported anymore). I am attempting to spawn rocks on the ground the the player collides with. I have made collision with many other objects in the game, but for some reason it's not working on these rocks.

Whenever I run the code I get a Null reference exception on line 146 of my room.cs (see first link below)

I have only tried adding collision to the first rock in the first case of the switch statement in my room.cs, so ignore the the other statements in the switch beyond line 146, they are there just to draw the textures in the correct place.

If there is anything more I need to add please say so. Like I said this is my first time posting here so I may not be very good at this.

Room.cs http://pastebin.com/WeYSpBZa (line 146 is where the error occurs on runtime)

Rock.cs (didn't know if you needed this to help figure it out, so I added it anyway) http://pastebin.com/6NYZrFir

  • possible duplicate of [What is a NullReferenceException and how do I fix it?](http://stackoverflow.com/questions/4660142/what-is-a-nullreferenceexception-and-how-do-i-fix-it) `rockList` is almost certainly null/Nothing – Ňɏssa Pøngjǣrdenlarp Dec 26 '14 at 01:21

1 Answers1

0

Your rocklist is null. Instantiate this field in the constructor : rockList = new List<Rock>();

Sievajet
  • 3,283
  • 2
  • 15
  • 22