0

I've declared an array of 88 arraylists using the following code:

Dim Data_FRONT(88) As ArrayList

and then I try to add incoming data to it using the following code:

Dim Data_In(88) As Double
For i = 0 To 87
    Data_In(i) = 15 ' Hard-coding just to test it
Next

' ...

' Then later in the code after some processing 
For i = 0 To 87
    Data_FRONT(i).Add(Data_In(i))        
Next

and I get the following run-time error: "Object reference not set to an instance of an object."

I've even tried doing this:

For i = 0 to 87
    Data_FRONT(i).Add(15) ' Hard-coding to test it
Next

and I still get that error. Any thoughts?

1 Answer 1

2

You need to actually initialize each array list:

For i = 0 To 87
    Data_FRONT(i) = new ArrayList() ' Initialize each ArrayList
    Data_FRONT(i).Add(Data_In(i))        
Next

That being said, if you are always storing an array of doubles, why not just make a single multi-dimensional array?

Dim Data(88,88) As Double = new Double(88, 88)
Sign up to request clarification or add additional context in comments.

4 Comments

Thanks! I'm actually collecting data from 88 different sensors, so I want the size of the data structure to increase dynamically.
@nsax91 You should consider using List(Of T) then, instead of ArrayList.
What's the advantage of using Lists instead of ArrayLists?
@nsax91 Type safety + speed (no boxing with value types, like double)

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.