locked
Null Reference Exception while trying to initialise an Integer array RRS feed

  • Question

  • User1578605183 posted

    Hi ,

    I am getting System.NullReferenceException:Object reference not set to an instance of an object

    while executing the below code..!!

    Dim arr() As Integer

    Dim g,j As Integer

    g=10

    j=0

    While g > 0
                    arr(j) =0
                    g = g - 1
                    j = j + 1
    End While

    Could anybody help me out..!!!

    Thanks in advance

    Sunday, May 15, 2011 2:13 AM

Answers

  • User-1360095595 posted

    Not a VB person, but I think you're missing the part where you need to initialize the array.  Anyway, the following link should help: http://msdn.microsoft.com/en-us/library/wak0wfyt.aspx

    • Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
    Sunday, May 15, 2011 7:55 AM
  • User-1179452826 posted

    Arrays are fixed in size. As such, you need to declare the size:

    Dim arr As Integer() = New Integer(10) {} 

    • Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
    Sunday, May 15, 2011 9:09 AM

All replies

  • User-1360095595 posted

    Not a VB person, but I think you're missing the part where you need to initialize the array.  Anyway, the following link should help: http://msdn.microsoft.com/en-us/library/wak0wfyt.aspx

    • Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
    Sunday, May 15, 2011 7:55 AM
  • User-1179452826 posted

    Arrays are fixed in size. As such, you need to declare the size:

    Dim arr As Integer() = New Integer(10) {} 

    • Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
    Sunday, May 15, 2011 9:09 AM