Object reference not set to an instance of an object RRS feed

  • Question

  • I wrote an ASPX file in VB.NET. Originally this file ran successfully but after adding one additional parameter it now fails on "Object reference not set to an instance of an object" on line "peType.DataSource = arrPEType" below.

    This error does not make sense to me though because I have similar parameter, 'dType', which it does not error on. What is the cause of this error?

    Here is some of my ASPX code file:

    Sub Page_Load(Sender as Object, E as EventArgs)
        If Not IsPostback Then 
          Dim TheMonthDate As Date = DateAdd(DateInterval.Month, -1, Today)
          calStartDate.SelectedDate = CDate((TheMonthDate.Month) & "/1/" & Year(TheMonthDate)).ToString("MM/dd/yyyy")
          calEndDate.SelectedDate = GlobalFunctions.GlobalF.MonthLastDate(CDate((TheMonthDate.Month) & "/1/" & Year(TheMonthDate)).ToString("MM/dd/yyyy"))
          Dim arrType as New ArrayList()
          Dim arrOrgUnit as New ArrayList()
          Dim arrPEType as New ArrayList()
          Dim peType As ListBox
          arrType.Add("Product and Process")
          dType.DataSource = arrType
          peType.DataSource = arrPEType
          'peType.DataTextField = "DisplayColumnName"
          'peType.DataValueField = "ValueColumnName"
          Dim TheType as String
          Dim TheOrgUnit as String
          Dim PE_Type as String
          Select Case dType.SelectedValue
            Case "Product and Process": 
            Case "Product": 
            Case "Process": 
          End Select
          Select Case peType.SelectedValue
            Case "INC": 
              PE_Type = "substring(a.QXP_EXCEPTION_NO, charindex('-', a.QXP_EXCEPTION_NO)+1, 4)='INC'"
            Case "NC": 
              PE_Type = "substring(a.QXP_EXCEPTION_NO, charindex('-', a.QXP_EXCEPTION_NO)+1, 4)='NC'"
            Case "QC": 
              PE_Type = "substring(a.QXP_EXCEPTION_NO, charindex('-', a.QXP_EXCEPTION_NO)+1, 4)='QC'"
          End Select
                Product Exception Type:
                <ASP:DROPDOWNLIST ID="peType" RUNAT="Server" AUTOPOSTBACK="true" />


    Ryan D
    • Moved by Mike Feng Monday, June 27, 2011 10:50 AM ASP.net (From:Visual Basic General)
    Friday, June 24, 2011 12:48 PM


  • Hi,

    This is the most common problem in VB.Net. The principle is the same even in an ASP.Net application ( using .aspx pages ).

    For further ASP.NET problems please visit:>>



    Try using the keyword NEW

    in order to set an instance variable to an NEW instance.

    Public Class Form1
      Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
        'At this point myBtn is NOTHING :>>
        Dim myBtn As Button
        'After this line of code myBtn is now a NEW Button:>>
        myBtn = New Button
        'No more "Object reference not set to an instance of an object"
        Dim myButtons(10) As Button
        For index As Integer = 0 To 10
          'Please note you need to set up ARRAYs with a NEW instance for every array member too:>>
          myButtons(index) = New Button
      End Sub
    End Class



    Click this link to see how to insert a picture into a forum post.

    Installing VB6 on Windows 7

    XNA is coming to VB.Net

    App Hub forums

    • Marked as answer by ironryan77 Wednesday, June 29, 2011 11:25 PM
    Friday, June 24, 2011 1:05 PM