ArrayLIst as a component of a class

  • Thread starter Thread starter =?ISO-8859-1?Q?Bernard_Bour=E9e?=
  • Start date Start date
?

=?ISO-8859-1?Q?Bernard_Bour=E9e?=

I have a class named INDICE that have two properties NAME and COMP
Name is declared as string
COMP is declared as an ArrayList

I have the following code

Dim Ind as New Indice
Ind.Name="Something"

Ind.Comp.Add("XXX")

THis last line give me an error "The reference to an object is not
referenced to its intance"

Thanks for your help

Bernard
 
Hi there... Where are you instantiating the arraylist object? This error
happens because its value is nothing (null). You can instantiate it in the
constructor or just where it is declared... For example

Class INDICE
private m_name As String, _
m_comp As ArrayList

Public Sub New()
m_comp = New ArrayList
End Sub

' Properties come here... they expose my class' private fields
End Class

Or like this..

Class INDICE
private m_name As String, _
m_comp As New ArrayList

Public Sub New()
End Sub

' Properties come here... they expose my class' private fields
End Class

Regards,
 
Thanks Angel

Bernard

Angel J. Hernández M. a écrit :
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Back
Top