我想爲我的鑽石遊戲顯示一組鑽石。一切看起來都很好,但我爲粗體(或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