Take the 2-minute tour ×
Game Development Stack Exchange is a question and answer site for professional and independent game developers. It's 100% free, no registration required.

I keep getting a "NullReferenceExeption was unhandled" with "Object reference not set to an instance of an object." written under it. I have all of the images (png) correct with names and added to references.

protected override void LoadContent()
{
    spriteBatch = new SpriteBatch(GraphicsDevice);
    backGround = Content.Load<Texture2D>("Cracked");
    player1.playerBlock = Content.Load<Texture2D>("square");
    player2.playerBlock = Content.Load<Texture2D>("square2");
}
share|improve this question
    
Where do you declare spriteBatch or backGround? Do you have a stack trace? –  ktodisco Oct 29 '12 at 3:18
2  
For one, if we're talking XNA here it's aTexture2DObject = Content.Load<Texture2D>("fileName"); Furthermore, are your objects player1 and player2 actually initialized by the time you reach this part of the code? –  Dialock Oct 29 '12 at 3:31
    
The problem is with the "splayer1.playerBlock = Content.Load("square");" and "player1.playerBlock = Content.Load("square2");" lines –  Seth Taddiken Oct 29 '12 at 3:34
5  
Again, the player1 and player2 objects need to exist before you can modify their member variables. Your error message is telling you that the thing you want to change doesn't even exist... so create it. Like Player player1 = new Player(); –  Dialock Oct 29 '12 at 4:24
    
THANK YOU DIALOCK!!!! –  Seth Taddiken Oct 29 '12 at 21:58
show 3 more comments

closed as too localized by Tetrad Jan 7 '13 at 23:32

This question is unlikely to help any future visitors; it is only relevant to a small geographic area, a specific moment in time, or an extraordinarily narrow situation that is not generally applicable to the worldwide audience of the internet. For help making this question more broadly applicable, visit the help center.If this question can be reworded to fit the rules in the help center, please edit the question.

Browse other questions tagged or ask your own question.