troubleshooting Question adding to array list error

Avatar of NCSA SCADA
NCSA SCADAFlag for United States of America asked on
ASP.NETVisual Basic.NET
2 Comments1 Solution349 ViewsLast Modified:
I have a project I am working on that is giving me fits.
I read in a comma seperated file.  loop until EndofStream - works great to this point - I have an object named city with the following properties (name, airfare, carrental, hotel)
i set the value of the properties based on what is read from the text file... everything still works great.... last but not least I add properties to a collection list... well i try... this is where it errors..... +            System.NullReferenceException      {"Object reference not set to an instance of an object."}      System.NullReferenceException

I am just stuck here .. any help would be great
 Private Shared Function Build(ByVal srCity As IO.StreamReader, _
                           ByRef colCities As List(Of City), _
                           ByRef strError As String) As Boolean
        '*  Reads through the City file designated by srFile
        '*  Building the City collection colCities
        '*  Parameters: 
        '*      srCity      stream reader of the City filr
        '*      colCities   collection of cities with names and prices
        '*      strError    If there is an error, it is returned here
        '*  Returns True if file was successfully read
        '*          False if not
        Const c_chrComma As Char = ","c
        Const c_strCityInvalidFormat As String = mc_strCity + " invalid format"

        Dim a_strCity() As String
        Dim objCity As New City

            Do Until srCity.EndOfStream

                a_strCity = srCity.ReadLine.Split(c_chrComma)

                objCity.Name = a_strCity(0)
                objCity.Airfare = Convert.ToDecimal(a_strCity(1))
                objCity.CarRental = Convert.ToDecimal(a_strCity(2))
                objCity.Hotel = Convert.ToDecimal(a_strCity(3))

            Return True
        Catch ex As Exception
            strError = c_strCityInvalidFormat
            Return False
        End Try

    End Function
Dirk Haest
Project manager

Our community of experts have been thoroughly vetted for their expertise and industry experience.

Join our community to see this answer!
Unlock 1 Answer and 2 Comments.
Start Free Trial
Learn from the best

Network and collaborate with thousands of CTOs, CISOs, and IT Pros rooting for you and your success.

Andrew Hancock - VMware vExpert
See if this solution works for you by signing up for a 7 day free trial.
Unlock 1 Answer and 2 Comments.
Try for 7 days

”The time we save is the biggest benefit of E-E to our team. What could take multiple guys 2 hours or more each to find is accessed in around 15 minutes on Experts Exchange.

-Mike Kapnisakis, Warner Bros