我想为我的钻石游戏显示一组钻石。一切看起来都很好,但我为粗体(或2 **)放置的行得到'NullReferenceException'错误。该项目称为Descending Diamonds,图像位于图形文件夹中。NullReferenceException
任何人都可以阐明一些事情。
// Initialize graphics library.
// Which graphics set are we using?
if (GameForm.ClientRectangle.Height < 480)
{
// The screen height is insufficient for the large graphics set,
// so load the small graphics
GameGraphics.Clear();
**GameGraphics.Add("Diamonds", new Bitmap(asm.GetManifestResourceStream("DecendingDiamonds.Graphics.SmallDiamonds.png")));**
_diamondWidth = 21;
_diamondHeight = 16;
}
else
{
// We have enough space to use the large graphics set
GameGraphics.Clear();
**GameGraphics.Add("Diamonds", new Bitmap(asm.GetManifestResourceStream("DecendingDiamonds.Graphics.BigDiamonds.png")));**
_diamondWidth = 42;
_diamondHeight = 32;
}
您是否构建了GameGraphics变量? – 2011-03-16 17:35:18
我认为他确实构建了GameGraphics变量,否则他会在他对同一对象调用Clear方法之前在线上得到该异常。 – Lav 2011-03-16 17:38:27
你可以发布堆栈跟踪吗? – 2011-03-17 09:51:21