分配值?

时间:2015-11-25 02:50:02

标签: vb.net

我有这个

 Public Shared Sub Button9_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button9.Click
    Dim c As Client
    Dim Armor As Item = c.Inventory.GetItemInSlot(SlotNumber.Armor)
End Sub

当我点击按钮时,崩溃并且" System.NullReferenceException"弹出,我已经四处搜索,发现它发生了,因为在分配值之前使用了c,所以我想知道,为它赋值的正确方法是什么?

1 个答案:

答案 0 :(得分:2)

试试这个:

而不是:

Public Shared Sub Button9_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button9.Click
    Dim c As New Client
    Dim Armor As Item = c.Inventory.GetItemInSlot(SlotNumber.Armor)
End Sub

尝试:

Public Shared Sub Button9_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button9.Click
    Dim c As New Client.Inventory
    Dim Armor As Item = c.Inventory.GetItemInSlot(SlotNumber.Armor)
End Sub