title: VB.net classes - Object reference not set to an instance of an object?
body: <p>I'm working on an application in VB that is giving me some trouble. Coming from Java and C++, the class syntax for VB is peculiar. I have my main form, and a class I created called <code>WebElement</code>. I imported the class to <code>MainForm.vb</code> and declared an array of <code>WebElement</code>'s. When I try to set or get the <code>Name</code> attribute of the first element of my array of 'WebElement`'s, it gives me an error - <strong>"Object reference not set to an instance of an object?"</strong> What does this mean, and how do I fix it?</p>
  
  <p><strong>Code</strong> <br />
  <code>MainForm.vb</code></p>
  
  <pre><code>Imports MyProgram.WebElement
  
  Public Class MainForm
  
      Private webpage(0 To 9) As WebElement
      Private pageNum As Integer = 0
  
      Private Sub openFile() Handles OpenToolStripMenuItem.Click
          webpage(pageNum).setName("rawr")
          MsgBox(webpage(pageNum).getName())
      End Sub
  
  End Class
  </code></pre>
  
  <hr />   
  
  <p><code>WebElement.vb</code></p>
  
  <pre><code>Public Class WebElement
  
      Private Name As String
  
      Public Function setName(ByRef n As String)
          Name = n
      End Function
  
      Public Function getName()
          Return Name
      End Function
  
  End Class
  </code></pre>