Using a collection (of objects) in a class
Posted on 2009-12-22
I have a class calledPlayer and a class called Parent.
The player class has a field called mParents and a property called Parents.
mParents is a collection. This way each player can have multiple parents.
At this point I have a very simple addParent method in Player that looks like this.
Public Sub addParent(ByVal value As Parent)
Dim mParent = New Collection
I use this method this way.
Private Sub addAParent(ByVal newPlayer As Player, ByVal nameOfParent As Parent)
Dim aplayer As Player
aplayer = New Player
aplayer = newPlayer
Dim aPorG As ParentorGuardian
aPorG = New ParentorGuardian
aPorG = nameOfParent
TextBox2.Text = aplayer.Parent.Item(1)
I get the error.... Object reference not set to an instance of an object.
aPlayer has it's info, aPoG has it's info.
What am I doing wrong?