G
Guest
Please I am trying to understand the arraylist.
Please anyone help; why I am getting this message "Object reference not set
to an instance of an object" when line no (13) get executed in the following
code:
1- ' Create a new ArrayList to hold the Customer objects.
2- Dim customerArray As New ArrayList()
3- 'Add customers to the ArrayList of Customer objects.
4- Dim x As Integer
5- For x = 0 To 999
6- customerArray.Add(New Customer("Customer" + x.ToString()))
7- Next x
8- ' Add orders to each Customer object in the ArrayList.
9- Dim customer1 As Customer
10- For Each customer1 In customerArray
11- Dim y As Integer
12- For y = 0 To 14
13- customer1.CustomerOrders.Add(New Order("Order" +
y.ToString()))
14- Next y
-----------Customer & Order Classes-----
Public Class Customer
Private _CustomerOrders As ArrayList
Private _Name As String
Public Property Name() As String
Get
Return _Name
End Get
Set(ByVal value As String)
_Name = value
End Set
End Property
Public Property CustomerOrders() As ArrayList
Get
Return _CustomerOrders
End Get
Set(ByVal value As ArrayList)
_CustomerOrders = value
End Set
End Property
Public Sub New(ByVal Name As String)
_Name = Name
End Sub
End Class
---------------
Public Class Order
Private _Name As String
Public Property Name() As String
Get
Return _Name
End Get
Set(ByVal value As String)
_Name = value
End Set
End Property
Public Sub New(ByVal Name As String)
_Name = Name
End Sub
End Class
Please anyone help; why I am getting this message "Object reference not set
to an instance of an object" when line no (13) get executed in the following
code:
1- ' Create a new ArrayList to hold the Customer objects.
2- Dim customerArray As New ArrayList()
3- 'Add customers to the ArrayList of Customer objects.
4- Dim x As Integer
5- For x = 0 To 999
6- customerArray.Add(New Customer("Customer" + x.ToString()))
7- Next x
8- ' Add orders to each Customer object in the ArrayList.
9- Dim customer1 As Customer
10- For Each customer1 In customerArray
11- Dim y As Integer
12- For y = 0 To 14
13- customer1.CustomerOrders.Add(New Order("Order" +
y.ToString()))
14- Next y
-----------Customer & Order Classes-----
Public Class Customer
Private _CustomerOrders As ArrayList
Private _Name As String
Public Property Name() As String
Get
Return _Name
End Get
Set(ByVal value As String)
_Name = value
End Set
End Property
Public Property CustomerOrders() As ArrayList
Get
Return _CustomerOrders
End Get
Set(ByVal value As ArrayList)
_CustomerOrders = value
End Set
End Property
Public Sub New(ByVal Name As String)
_Name = Name
End Sub
End Class
---------------
Public Class Order
Private _Name As String
Public Property Name() As String
Get
Return _Name
End Get
Set(ByVal value As String)
_Name = value
End Set
End Property
Public Sub New(ByVal Name As String)
_Name = Name
End Sub
End Class