title: Null Reference Exception VB
body: <p>New to VB.net, frustrated have been looking at this all day, Why PbAlly() value is Nothing ?</p>
  
  <p>my screenshoot :</p>
  
  <p><a href="https://i.stack.imgur.com/oqX9Q.png" rel="nofollow noreferrer">Null Reference Exception error</a></p>
  
  <p>Code look like :</p>
  
  <pre><code>Public Class Form1
  Dim thdUDPServer
  Dim Playing As Boolean = False
  Dim Giliran As Boolean = False
  
  Dim PbAlly() As PictureBox = {pbAlly1, pbAlly2, pbAlly3, pbAlly4, pbAlly5, pbAlly6, pbAlly7}
  
  Dim Kartu As Integer = 0
  
  Public Sub initGame()
      Dim RandomClass As New Random()
      Dim RememberSet As New HashSet(Of Integer)
  
      Dim RandomNumber As Integer
  
      While RememberSet.Count &lt; 7
          RandomNumber = RandomClass.Next(1, 14)
          If RememberSet.Add(RandomNumber) Then
              If RandomNumber = 11 Then
                  lbData.Items.Add("*J")
              ElseIf RandomNumber = 12 Then
                  lbData.Items.Add("*Q")
              ElseIf RandomNumber = 13 Then
                  lbData.Items.Add("*K")
              Else
                  lbData.Items.Add("*" &amp; RandomNumber)
              End If
              PbAlly(Kartu).Image = Card.My.Resources.ResourceManager.GetObject(RandomNumber)
              Kartu += 1
          End If
      End While
  End Sub
  </code></pre>
  
  <p><code>PbAlly()</code> always giving me a null reference exception and I don't know why ?</p>
  
  <p>Thanks for the help in advance.</p>