我有这个
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,所以我想知道,为它赋值的正确方法是什么?
答案 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