对象引用未设置到对象的实例 - 错误
Object reference not set to an instance of an object - Error
我有一个枚举,它是数组列表(它是可选的,您最多可以添加 5 次)
Public DiseaseTreatment() As TreatmentsetDiseaseTreatment
Public Enum TreatmentsetDiseaseTreatment
'''<remarks/>
<System.Xml.Serialization.XmlEnumAttribute("01")> _
Item01
''<remarks/>
Antibiotics
''<remarks/>
<System.Xml.Serialization.XmlEnumAttribute("02")> _
Item02
'''<remarks/>
<System.Xml.Serialization.XmlEnumAttribute("Pain Killers)")> _
PainKillers
中断
Dim temptreatment As List(Of TreatmentsetDiseaseTreatment)= New List(Of TreatmentsetDiseaseTreatment)()
temptreatment.Add("Painkiller")
For i As Integer = 0 To temptreatment(i) - 1
test.TreatmentTypes(i) = temptreatment(i)
Next
当我将鼠标悬停在 tempTreatment(i)
上时,它有正确的字符串 "painkiller"
所以我不明白它是如何抛出 NullReferenceException
?
您想在数组末尾停止,而不是在数组中第 x 项的末尾。
For i As Integer = 0 To temptreatment.Count - 1
没有
For i As Integer = 0 To temptreatment(i) - 1
我有一个枚举,它是数组列表(它是可选的,您最多可以添加 5 次)
Public DiseaseTreatment() As TreatmentsetDiseaseTreatment
Public Enum TreatmentsetDiseaseTreatment
'''<remarks/>
<System.Xml.Serialization.XmlEnumAttribute("01")> _
Item01
''<remarks/>
Antibiotics
''<remarks/>
<System.Xml.Serialization.XmlEnumAttribute("02")> _
Item02
'''<remarks/>
<System.Xml.Serialization.XmlEnumAttribute("Pain Killers)")> _
PainKillers
中断
Dim temptreatment As List(Of TreatmentsetDiseaseTreatment)= New List(Of TreatmentsetDiseaseTreatment)()
temptreatment.Add("Painkiller")
For i As Integer = 0 To temptreatment(i) - 1
test.TreatmentTypes(i) = temptreatment(i)
Next
当我将鼠标悬停在 tempTreatment(i)
上时,它有正确的字符串 "painkiller"
所以我不明白它是如何抛出 NullReferenceException
?
您想在数组末尾停止,而不是在数组中第 x 项的末尾。
For i As Integer = 0 To temptreatment.Count - 1
没有
For i As Integer = 0 To temptreatment(i) - 1