4

I have a simple problem, but I can't solve it even with the Internet... I don't know what is wrong.

I defined a variable:

Dim paczka(1) As SenditAPI.singleSizesData 

singleSizesData is a structure and I need an array of this structure

And then I try:

paczka(0).width = 10
paczka(0).height = 10
paczka(0).depth = 10
paczka(0).weight = 4
paczka(0).COD = 0
paczka(0).INS = 5
paczka(0).content = "Test"

I get the "An unhandled exception of type 'System.NullReferenceException'" error. I really don't know why.

3
  • On which line do you get that error? I tried a quick example and your code and it works perfectly ok. Commented Aug 20, 2014 at 8:23
  • @AdamHouldsworth No I haven't initialised but I tried and I got the same error in the same place. In documentation is written that singleSizesData is an array structure. @PradeepKumar I get that error in this line - paczka(0).width = 10 Commented Aug 20, 2014 at 8:33
  • 2
    If you are getting error on that line, then surely your singleSizesData is not a structure but a class. This is because strucures don't need to be initialized, while classes do need initialization (using the new keyword). You can verify this by initializing it like paczka(0) = New SenditAPI.singleSizesData before that line. If it works, then surely it is a Class, and not a Structure. Please verify. Commented Aug 20, 2014 at 8:48

1 Answer 1

2

You say that SenditAPI.singleSizesData is a structure but in order to get the error you experience it must be a class because clearly paczka(0) is null and structures cannot be null. So the problem is that you create an array with null references that you then try to dereference resulting in the exception.

You will have to create a new SenditAPI.singleSizesData instance before assigning its members:

paczka(0) = new SenditAPI.singleSizesData
paczka(0).width = 10
paczka(0).height = 10
paczka(0).depth = 10
paczka(0).weight = 4
paczka(0).COD = 0
paczka(0).INS = 5
paczka(0).content = "Test"
Sign up to request clarification or add additional context in comments.

Comments

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.