|
-
Oct 15th, 2023, 10:08 PM
#1
Thread Starter
Frenzied Member
[RESOLVED] An error occurred creating the form
This has happened on the last 3 projects i created.
All projects only had a textbox and button with basic code.
If i comment out all code in the form, project runs.
Application.Designer.vb
Code:
'------------------------------------------------------------------------------
' <auto-generated>
' This code was generated by a tool.
' Runtime Version:4.0.30319.42000
'
' Changes to this file may cause incorrect behavior and will be lost if
' the code is regenerated.
' </auto-generated>
'------------------------------------------------------------------------------
Option Strict On
Option Explicit On
Namespace My
'NOTE: This file is auto-generated; do not modify it directly. To make changes,
' or if you encounter build errors in this file, go to the Project Designer
' (go to Project Properties or double-click the My Project node in
' Solution Explorer), and make changes on the Application tab.
'
Partial Friend Class MyApplication
<Global.System.Diagnostics.DebuggerStepThroughAttribute()> _
Public Sub New()
MyBase.New(Global.Microsoft.VisualBasic.ApplicationServices.AuthenticationMode.Windows)
Me.IsSingleInstance = false
Me.EnableVisualStyles = true
Me.SaveMySettingsOnExit = true
Me.ShutDownStyle = Global.Microsoft.VisualBasic.ApplicationServices.ShutdownMode.AfterMainFormCloses
End Sub
<Global.System.Diagnostics.DebuggerStepThroughAttribute()> _
Protected Overrides Sub OnCreateMainForm()
Me.MainForm = Global.NewClientConsole.Form1 'ERROR HERE
End Sub
End Class
End Namespace
ERROR
System.InvalidOperationException
HResult=0x80131509
Message=An error occurred creating the form. See Exception.InnerException for details. The error is: Object reference not set to an instance of an object.
Source=NewClientConsole
StackTrace:
at NewClientConsole.My.MyProject.MyForms.Create__Instance__[T](T Instance) in :line 190
at NewClientConsole.My.MyProject.MyForms.get_Form1()
at NewClientConsole.My.MyApplication.OnCreateMainForm() in C:\Users\mcapp\OneDrive\Documents\Visual Studio 2017\NewClientConsole\NewClientConsole\My Project\Application.Designer.vb:line 35
at Microsoft.VisualBasic.ApplicationServices.WindowsFormsApplicationBase.OnRun()
at Microsoft.VisualBasic.ApplicationServices.WindowsFormsApplicationBase.DoApplicationModel()
at Microsoft.VisualBasic.ApplicationServices.WindowsFormsApplicationBase.Run(String[] commandLine)
at NewClientConsole.My.MyApplication.Main(String[] Args) in :line 81
Inner Exception 1:
NullReferenceException: Object reference not set to an instance of an object.
-
Oct 15th, 2023, 10:25 PM
#2
Thread Starter
Frenzied Member
[RESOLVED]Re: An error occurred creating the form
opps, had this , sorry
so ClientName was expecting to have a value which looks like its the problem.
Code:
Public Class Form2
Dim ClientName As String = TxtName.Text
-
Oct 15th, 2023, 10:30 PM
#3
Re: An error occurred creating the form
You are almost certainly running in to an issue where TxtName doesn't yet exist when that line of code is being executed.
Change it to:
Code:
Dim ClientName As String
Then, in the Form_Load event, add:
Code:
ClientName = TxtName.Text
-
Oct 15th, 2023, 11:33 PM
#4
Re: An error occurred creating the form
 Originally Posted by OptionBase1
Change it to:
Code:
Dim ClientName As String
Really ought to be:
Code:
Private ClientName As String
Always better to be explicit about access level.
 Originally Posted by OptionBase1
Then, in the Form_Load event, add:
Code:
ClientName = TxtName.Text
That would accomplish what the original code appears to intend, but is that worthwhile anyway? What's the point in getting the Text from a TextBox that the user hasn't even seen yet, thus could not have populated yet? If that TextBox is populated via a bound setting or the like, then the field should be populated from that setting rather than from the control.
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|