I have an ArrayList
defined in Class A
. Then I want to build this array in Class B
and use it in Class A
.
I defined the ArrayList as:
Public arrayList As ArrayList
Then, in Class B
I do:
Dim trLogkEmpty As New A
'Loop with strEspece definition
trLogkEmpty.arrayList.Add(strEspece)
'End Loop
The program throws me this error:
NullReferenceException
I don't know why, because strEspece
has never become null (I tested it). I don't know if there is another reason.
Also, when I loop through the arrayList
elements in Class A
, I get again NullReferenceException
. This is the loop code:
For Each logkNull In Me.arrayElemWithLogkEmpty
Console.WriteLine(logkNull)
Next
I don't know what happens with the first exception, but the code runs "correctly". In the second exception I guess that is something like I'm loosing the elements values of the array. I don't know how to solve it...any help? I accept different ways to solve it!