Here are my definitions:
Public Class RouteDetails
Public strRoad As String
Public strToLane As String
Public strToDirection As String
End Class
Public Class Route
Public lstRouteDetails As List(Of RouteDetails)
End Class
ByVal lstRouteList As List(Of Route) (part of a function definition)
Sorry I tried to put the definitions section into a code block but, for some reason, it's not working.
Here is a section of the code, from that function, that I'm having problems with:
rlcRoute = New Route
lstRouteList.Add(rlcRoute)
rdcRouteStep.strRoad = sdrNextJunction.GetValue(3)
rdcRouteStep.strToLane = sdrNextJunction.GetValue(2)
rdcRouteStep.strToDirection = sdrNextJunction.GetValue(1)
For intloop = 0 To lstRouteList.Count - 1
lstRouteList(intloop).lstRouteDetails.Add(rdcRouteStep)
Next
The line, within the for loop, fails with:
System.NullReferenceException: 'Object reference not set to an instance of an object.'
System.Collections.Generic.List.this[int].get.lstRouteDetails was Nothing.
If I understand the error correctly then it's telling me that I haven't created an instance of lstRouteDetails for this instance of Route? If that's correct then I would appreciate some advice on how to achieve this? I've tried a few combinations. The structure I'm trying to have is as follows:
RouteList is a list of objects of type route
Each Route object contains several objects of type RouteDetails
Thanks