Still new to OOP, and can’t figure out what I’m missing….
In VB.Net, in class Class1, I have defined class FormFld:
Public Class FormFld
Public Property ScrField As Control ' A control on the form
Public Property DbField As String ' Its corresponding field name in the database
End Class
Also in Class1, I define an object, Indiv, which contains FormFlds, which will hold a list of FormFld objects:
Public Class Indiv
Public FormFlds As List(Of FormFld) ' List
Public Sub New()
End Sub
End Class
It seems to me that my constructor doesn’t need to do much.
Later on, one of my Windows forms attempts to create an Indiv object and store its form information in FormFlds:
Dim ff As New Indiv()
ff.FormFlds.Add(New FormFld With {.ScrField = TxtFullName, .DbField = "LastName" })
Setting a breakpoint and stepping through the code, I see that the Dim is successful, and I get a new Indiv object. However, when executing the ff.FormFlds.Add, I receive
System.NullReferenceException: 'Object reference not set to an instance of an object.'
Can anyone tell me what I’m doing wrong?