你调用的对象是空的?网络

发布于 2024-12-10 10:34:45 字数 431 浏览 1 评论 0原文

我这里有这样的代码:

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 行上发生的错误 对象引用未设置到对象的实例。这是为什么呢?我该如何解决这个问题?

I have this code here:

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

Which gives me the error Object reference not set to an instance of an object occuring on the Do Until line. Why is this? How can I fix this?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

享受孤独 2024-12-17 10:34:45

MasterIndex 变量从未被分配,这就是为什么出现异常的原因。

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

 Dim MasterIndex As new String()()

并在调用 Lookup 函数之前用数据填充它。

像这样的东西:

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

The MasterIndex variable is never assigned that is why you have the exception

You should instantiate MasterIndex first by calling the New() constructor:

 Dim MasterIndex As new String()()

and fill it with data before calling the Lookup function.

Something like:

 Private MasterIndex As String()() = New String()() {New String() {"A1", "A2"}, New String() {"B1", "B2"}}
不疑不惑不回忆 2024-12-17 10:34:45

MasterIndex 未初始化或 MasterIndex(0) 未初始化。

假设您在程序的其他地方执行此操作,您能否显示初始化该变量的代码?

如果您在该行上放置一个断点并检查 MasterIndex 会发生什么?

Either MasterIndex is not initialized or MasterIndex(0) is not initialized.

Can you show the code that initializes that variable, assuming you do that somewhere else in the program?

What happens if you put a breakpoint on that line and examine MasterIndex?

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文