创建表单时发生错误.有关详细信息,请参见Exception.InnerException.错误是:对象引用未设置为对象的实例 [英] An error occurred creating the form. See Exception.InnerException for details. The error is: Object reference not set to an instance of an object

查看:67
本文介绍了创建表单时发生错误.有关详细信息,请参见Exception.InnerException.错误是:对象引用未设置为对象的实例的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

尝试调试表单时收到此错误,我根本看不到错误可能在哪里(也不突出显示在哪里),有人有任何建议吗?

创建表单时发生错误. 请参阅Exception.InnerException以获取 细节.错误是:对象 引用未设置为的实例 对象.

Dim dateCrap As String = "Date:"
Dim IPcrap As String = "Ip:"
Dim pcCrap As String = "Computer:"
Dim programCrap As String = "Program:"

Dim textz As String
Dim sep() As String = {vbNewLine & vbNewLine}
Dim sections() As String = Text.Split(sep, StringSplitOptions.None)

Dim NewArray() As String = TextBox1.Text.Split(vbNewLine)


Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
    textz = TextBox1.Text
End Sub

解决方案

错误在这里:

Dim textz As String = TextBox1.Text

在这里:

Dim NewArray() As String = TextBox1.Text.Split(vbNewLine)

可能在这里:

Dim sections() As String = Text.Split(sep, StringSplitOptions.None)

您不能像这样初始化成员,因为该代码基本上是在构造函数中执行的,是在之前 TextBox1(或任何其他控件/属性)初始化的,因此它是Nothing. /p>

将所有引用控件的初始化都放入Form_Load事件内-这就是它的作用.

I get this error when attempting to debug my form, I cannot see where at all the error could be (also does not highlight where), anyone have any suggestions?

An error occurred creating the form. See Exception.InnerException for details. The error is: Object reference not set to an instance of an object.

Dim dateCrap As String = "Date:"
Dim IPcrap As String = "Ip:"
Dim pcCrap As String = "Computer:"
Dim programCrap As String = "Program:"

Dim textz As String
Dim sep() As String = {vbNewLine & vbNewLine}
Dim sections() As String = Text.Split(sep, StringSplitOptions.None)

Dim NewArray() As String = TextBox1.Text.Split(vbNewLine)


Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
    textz = TextBox1.Text
End Sub

解决方案

The error is here:

Dim textz As String = TextBox1.Text

and here:

Dim NewArray() As String = TextBox1.Text.Split(vbNewLine)

and possibly here:

Dim sections() As String = Text.Split(sep, StringSplitOptions.None)

You cannot initialize a member like this because this code is basically executed in the constructor, before TextBox1 (or any other control/property) is initialized, hence it is Nothing.

Put all initializations that refer to controls inside the Form_Load event – that’s what it’s there for.

这篇关于创建表单时发生错误.有关详细信息,请参见Exception.InnerException.错误是:对象引用未设置为对象的实例的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆