Warning: file_get_contents(/data/phpspider/zhask/data//catemap/4/oop/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
对象引用未设置为对象的实例?VB.NET_Vb.net_Oop_Object Reference_Do Loops - Fatal编程技术网

对象引用未设置为对象的实例?VB.NET

对象引用未设置为对象的实例?VB.NET,vb.net,oop,object-reference,do-loops,Vb.net,Oop,Object Reference,Do Loops,我这里有这个代码: Dim MasterIndex As String()() Private Function Lookup(ByVal Search_path As String) As Integer Dim i As Integer = 0 Do Until MasterIndex(i)(0) Is Nothing If Search_path = MasterIndex(i)(0) Then Return MasterIndex

我这里有这个代码:

Dim MasterIndex As String()()

Private Function Lookup(ByVal Search_path As String) As Integer
    Dim i As Integer = 0
    Do Until MasterIndex(i)(0) Is Nothing
        If Search_path = MasterIndex(i)(0) Then
            Return MasterIndex(i)(1)
        End If
    Loop
    Return -1
End Function

这给了我错误
对象引用未设置为发生在
Do-Until
行上的对象的实例。为什么会这样?如何解决此问题?

从未分配MasterIndex变量,这就是为什么会出现异常

您应该首先通过调用New()构造函数实例化MasterIndex:

 Dim MasterIndex As new String()()
并在调用查找函数之前用数据填充它

比如:

 Private MasterIndex As String()() = New String()() {New String() {"A1", "A2"}, New String() {"B1", "B2"}}

MasterIndex变量从未赋值,这就是出现异常的原因

您应该首先通过调用New()构造函数实例化MasterIndex:

 Dim MasterIndex As new String()()
并在调用查找函数之前用数据填充它

比如:

 Private MasterIndex As String()() = New String()() {New String() {"A1", "A2"}, New String() {"B1", "B2"}}

主索引未初始化或主索引(0)未初始化

假设您在程序中的其他地方进行了初始化,您是否可以显示初始化该变量的代码


如果在该行上放置断点并检查主索引,会发生什么情况?

主索引未初始化或主索引(0)未初始化

假设您在程序中的其他地方进行了初始化,您是否可以显示初始化该变量的代码


如果在该行上放置断点并检查MasterIndex,会发生什么情况?

我会在Dim I上放置一个断点作为整数=0,然后查看MasterIndex中的内容,以缩小问题范围。你也可以用一个try-catch来包装这个块,看看它是否澄清了发生的事情。这不是一个解决方案,但它可能会帮助您确定问题。我会在Dim I上设置一个断点,作为Integer=0,然后查看masterIndex中的内容,以缩小问题范围。你也可以用一个try-catch来包装这个块,看看它是否澄清了发生的事情。这不是一个解决方案,但它可以帮助您识别问题。