title: visual basic: object reference not set to an instance of an object
body: <p>i watched a video tutorial and saw the guy write and execute the code below and worked but when i try to compile mine it says "object reference not set to an instance of an object". i have tried several things to see if i can get what the problem is but to no avail.</p>
  
  <pre><code>Imports System.IO
  Public Class Form2
  
      Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
          Try
              Dim myline = New StreamReader("TextFile1.txt")
              Dim line As String = ""
              While Not IsNothing(line)
                  line = myline.ReadLine
                  If IsNothing(line) Then
                      TextBox2.AppendText(line)
                  End If
              End While
              myline.Close()
  
          Catch ex As Exception
  
              TextBox2.AppendText(ex.Message)
              MsgBox(ex.Message)
  
          End Try
  
  
      End Sub
  
  End Class
  </code></pre>
  
  <p>can anyone help please? thanks</p>