-4
我從列表中讀取了一件盔甲的座標。當它發現特定的裝甲時,它應該攜帶該裝甲對象,並將其添加到另一個列表中。然而,我收到一個空對象錯誤(對象引用未設置爲對象的實例)?當我想從列表中添加時,爲什麼會收到空錯誤異常?
foreach (Armour item in armousOnMap)
{
if (item.Row == _yPosition && item.Column == _xPosition)
{
armourInventory.Add((Armour)item);
}
}
你確定'armourInventory'被初始化爲'new List'? –
MarcinJuraszek
2013-02-22 07:10:03
armourInventory是什麼,它是如何實例化的? – 2013-02-22 07:10:23
哪條線路故障?基本上,* something *爲null - 無論是'item'還是'armousOnMap'或'armourInventory'。除此之外,我們不能用這麼少的信息來幫助你。請參閱http://tinyurl.com/so-list – 2013-02-22 07:11:27