Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/visual-studio/8.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 System.InvalidOperationException:&x27;创建表单时出错_Vb.net_Visual Studio - Fatal编程技术网

Vb.net System.InvalidOperationException:&x27;创建表单时出错

Vb.net System.InvalidOperationException:&x27;创建表单时出错,vb.net,visual-studio,Vb.net,Visual Studio,在尝试运行/调试WindowsForm的代码时,我遇到以下异常: System.InvalidOperationException HResult=0x80131509消息=An 创建表单时出错。有关详细信息,请参阅Exception.InnerException 细节。错误是:对象引用未设置为 对象Source=自动声功率测试StackTrace:at 自动测试.My.MyProject.MyForms.Create\u\u实例\u[T](T 实例)输入:第190行 自动\u SoundPow

在尝试运行/调试WindowsForm的代码时,我遇到以下异常:

System.InvalidOperationException HResult=0x80131509消息=An 创建表单时出错。有关详细信息,请参阅Exception.InnerException 细节。错误是:对象引用未设置为 对象Source=自动声功率测试StackTrace:at 自动测试.My.MyProject.MyForms.Create\u\u实例\u[T](T 实例)输入:第190行 自动\u SoundPower\u测试.My.MyProject.MyForms.get\u Form1()位于 中的Automated\u SoundPower\u Testing.My.MyApplication.OnCreateMainForm() C:\Users\M0110823\source\repos\Automated SoundPower Testing\My Project\Application.Designer.vb:第35行 Microsoft.VisualBasic.ApplicationServices.WindowsFormsApplicationBase.OnRun() 在 Microsoft.VisualBasic.ApplicationServices.WindowsFormsApplicationBase.DoApplicationModel() 在 Microsoft.VisualBasic.ApplicationServices.WindowsFormsApplicationBase.Run(字符串[]) 命令行)在 中的自动\u SoundPower\u测试.My.MyApplication.Main(字符串[]Args) :第81行

内部异常1:NullReferenceException:对象引用未设置为 对象的实例。”

此例外情况涉及:

Me.MainForm=Global.Automated\u SoundPower\u Testing.Form1

我想这可能是因为我试图在创建.Mainform之前调用它?或者目录和项目属性之间可能存在命名错误?我创建了一个空白项目,并将代码/vb表单传输过来,遇到了相同的错误。 这让我相信我的代码中有一些错误

这是我代码的第一部分,之后的所有内容都被分类到Form1类下的区域中

Imports System.Windows.Forms
Imports System.Windows.Controls.Label
Imports System.IO
Imports System
Imports System.Text.RegularExpressions
Imports Microsoft.Office.Interop
Imports LMSTestLabAutomation
Imports System.IO.File
Imports System.IO.Path
Imports System.Threading
Imports System.ComponentModel
Imports System.Runtime.InteropServices

Class Form1
    Dim TL As LMSTestLabAutomation.Application
    Public tlDb As IDatabase
    Dim SaveDataName As String
    'Declare UA variables
    Dim UAmodel, UAtype, UAsn, UAoperator, UAdate, UAcomment,
        UAtesttype, UAtestpurpose, UAtime, UAtestduration As String
    Dim UAlist As New SortedList(Of String, String)
    Dim AcqState As String = "Acquisition Offline"
    Dim aRecordTime As Boolean() = New Boolean() {}
    Dim aRunNames As String() = New String() {}
    Dim aProjectNames As String() = New String() {}
    Dim aStatus As String() = New String() {}
    Dim aStartTrigger As Single() = New Single() {}
    Dim aStopTrigger As Single() = New Single() {}
    Dim aTriggerCondition As String() = New String() {}
    Dim aSequences As Integer() = New Integer() {}
    Dim newTestIncrement As Integer
    Dim newTest As String() = aRunNames
    'Declarations of the used objects
    Dim database As LMSTestLabAutomation.IDatabase
    Dim datawatch_pictManag As LMSTestLabAutomation.IDataWatch
    Dim WithEvents gDataWatch_AcqState As LMSTestLabAutomation.DataWatch
    Dim pictManag As LMSTestLabAutomation.IPictureManager
    Dim myPicture As LMSTestLabAutomation.IPicture
    Dim myBlock As LMSTestLabAutomation.IBlock2
    Dim myDisplay As LMSTestLabAutomation.IDisplay
    Dim Measure_Port As LMSTestLabAutomation.DataWatch
    Dim Open_book = TL.ActiveBook
    Dim sequence_number = Open_book(0, 2)

您是否有
表单1
或者您是否重命名了该类?引发异常的行是boiler plate Visual Studio自动生成的代码。您可能不应该修改该文件中的任何内容(是吗?)。请发布一些代码(这次不是在图像中,编辑您的问题,添加实际代码)因此,我们可以进一步帮助您。我不同意重复标记。OP有一些标准winforms代码引发异常-我个人不知道如果我想,我将如何使该行引发异常,因此可能会有更复杂的事情发生,这比结束更值得关注。Luke,请提供详细信息我在上面要求的表单,如果可以的话,我愿意提供帮助。正如图片中显示的消息所述,“创建表单时出错”。在本例中,表单1中的表单。错误发生在
Sub New()中
。如果您没有显式地编写
Sub-New
,请查看类级变量声明/初始值设定项,因为初始化部分将由编译器写入生成的
Sub-New
。即
将某物变暗为SomeObject=New SomeObject