简体   繁体   中英

Issue with LoadContent converting XNA 2.0 to 4.0

Hello I am doing this project in school and I ran into a problem when I got a pdf with instructions to make a small and simple game. There was all the code in the pdf but the problem is that my teacher wrote the code in XNA 2.0 and we are using XNA 4.0.

The thing is that in my LoadContent part of the Game1.cs there is a bit of code that dont work.

protected override void LoadContent()
{
    foreach (GameObject g in gameObjects)
    {
        g.LoadContent();
    }
    // Create a new SpriteBatch, which can be used to draw textures.
    spriteBatch = new SpriteBatch(GraphicsDevice);
    // TODO: use this.Content to load your game content here
}

The part of the code that fails is the g . When I try to Debug it shows this error message

An unhandled exception of type 'System.NullReferenceException' occurred in First XNA.exe Additional information: Objektreferensen har inte angetts till en instans av ett objekt.

I have no idea how to fix it. If you need more info please say it so I will try to provide it.

As the exception states : "NullReferenceError" means that g is null when you try to invoke LoadContent(). I have a feeling that you need to check gameObjects for consistency. Hope this helps!

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