0

CustomersFound is an ArrayList defined as follows:

Public CustomersFound As ArrayList

A NullReferenceException is thrown when I try to add to the collection.

CustomersFound.Add(Node)

The exact message states: "Object reference not set to an instance of an object".

I'm adding to the ArrayList in a public subroutine as follows:

Public Sub SearchTraverse(ByVal Node As Customer, Surname As String)
    ' Code to search for customers here...

    CustomersFound.Add(Node)
End Sub

Can anybody help me as to why I am getting this error?

Will Marcouiller
  • 23,773
  • 22
  • 96
  • 162
stizzo96
  • 666
  • 1
  • 7
  • 15

1 Answers1

2

The error means that CustomersFound does not exist. Check that whatever method you're using has actually created one. The code you have does not instantiate an ArrayList. Perhaps you should use:

Public CustomersFound As New ArrayList()
Joel Etherton
  • 37,325
  • 10
  • 89
  • 104
  • +1 The `NullReferenceException` is thrown when an object is accessed without having priorly being instantiated as per MSDN: http://msdn.microsoft.com/en-us/library/system.nullreferenceexception(v=vs.110).aspx?cs-save-lang=1&cs-lang=vb#code-snippet-1 – Will Marcouiller Mar 13 '14 at 15:03