Go Back   Zune Boards > Zune Discussions > Zune Games > Development Discussions > Development Help

Development Help For help from coding to error finding to that one thing you just can't get right

Reply
 
LinkBack Thread Tools
Old 10-20-2009, 12:45 PM   #1 (permalink)
Squirt
 
Join Date: Oct 2008
Posts: 26
Fallenarms3 is on a distinguished road
Default 'System.NullReferenceException'

Ok, I know this is like, my 3rd thread this week, but I'm really kind of frustrated. I get this error when I try to deploy my latest project:

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

That's all it says. The breakpoint it creates is at

Code:
GraphicsDevice.Clear(Color.Black);
Of all things. I'm pretty sure that line of code is NOT incorrect, but I tried deleting it, and it just gave the same error and broke it at the next line. So I'm pretty sure everything works until it begins the Draw method.

Here's the code in its entirety: pastebin - collaborative debugging tool



Fallenarms3 is offline   Reply With Quote

Advertisement [Remove Advertisement]
Old 10-20-2009, 02:04 PM   #2 (permalink)
lost in paradise with rae
Support Team
Moderator
Expert Zuner
 
Red Sky's Avatar
 
Join Date: Nov 2007
Location: Pennsylvania
Posts: 2,660
Red Sky is just really niceRed Sky is just really niceRed Sky is just really nice
Send a message via MSN to Red Sky
Default

I have a feeling that GraphicsDevice is null.

I don't see anything wrong with your code off-hand though...





Red Sky is offline   Reply With Quote
Old 10-20-2009, 04:40 PM   #3 (permalink)
Squirt
 
Join Date: Oct 2008
Posts: 26
Fallenarms3 is on a distinguished road
Default

Thanks for replying. With some help from the XNA forums, I got this sorted out.

Of course, that doesn't mean my blasted App runs....



Fallenarms3 is offline   Reply With Quote
Old 10-23-2009, 05:05 PM   #4 (permalink)
Jr. Member
 
Join Date: Jun 2007
Location: Mass
Posts: 332
shutout5591 will become famous soon enough
Default

System.NullReferenceException are one of the easiest exceptions to identify.

In C#, and most managed languages like Java, each variable like GraphicsDevice contains a reference in memory to the data for the object. so when this statement executes "WebClient client = new WebClient()" a webclient object is initialized, and client simply points to the webclient in memory.

So, when you get this error, you are trying to get the data from a reference that is not created yet. make sense?

A little debugging tip, putting your mouse over any variable (or type for that matter) in visual studio tells you the value of it. This will pin point which variable is declared (WebClient client but not initialized (client = new WebClient()

good luck on your app.
__________________
~Shutout5591~

[FINAL] Asteroids 1.0
If you like me work or I have helped you, + Rep me!




shutout5591 is offline   Reply With Quote
Reply

Bookmarks

Thread Tools