SyStem.NullReeferenceExeption error on mapDisplayDevice

Feb 20, 2011 at 4:53 PM
Edited Feb 20, 2011 at 5:06 PM

Hi....

i was doing all from tIDE tutorial but in line 

map.LoadTileSheets(mapDisplayDevice);

there is error 

An unhandled exception of type 'System.NullReferenceException' occurred in WindowsGame1.exe

Additional information: Object reference not set to an instance of an object.

help me to fix it :)

Uploaded with ImageShack.us

best regards, ceo

Feb 21, 2011 at 12:31 AM

I think you need to do the next step in the tutorial for it to work (step 11).

I suggest you do all the steps first, then run the code at the end.

Feb 21, 2011 at 4:49 PM
colinvella wrote:

I think you need to do the next step in the tutorial for it to work (step 11).

I suggest you do all the steps first, then run the code at the end.


i was doing like in tutorial was written :) same error! all steps was writed but nothing!!! :( i`ll try with newest release....

Feb 21, 2011 at 9:45 PM
Edited Feb 21, 2011 at 9:47 PM

From your screenshot, it is clear that, at the point the exception occurred, the map object was still null. That's probably because you have not yet specified the line

map = Content.Load("Maps\\Map01");

 

<map></map>

 

as per step 11 within the LoadContent method (which is actually called by XNA before the Initialize method).

 

You cannot assume that the program will always compile and/or run properly after each and every step in the tutorial :)

 

If you still have problems however, you could paste the source of Game1.cs as a post in here and I will have a look.

Apr 8, 2011 at 4:56 PM

Remove map.LoadTileSheets(mapDisplayDevice); from the Initialize method and place it in the LoadContent() method as seen below. This will allow it to load up with no problems.

protected override void LoadContent()
        {
            
            // Create a new SpriteBatch, which can be used to draw textures.
            spriteBatch = new SpriteBatch(GraphicsDevice);

           //Load xTile map from content pipeline
            map = Content.Load<Map>("Maps\\Map01");

            //Initialize xTile map resources
            map.LoadTileSheets(mapDisplayDevice);
        }