Help with System.NullReferenceException

Ask a Question related to ASP.NET General, Design and Development.

  1. #1

    Default Help with System.NullReferenceException

    I'm trying to fill an array of objects but when I add the first object I get
    a NullReferenceException.
    ----------------------------------------------------------------------------
    -------------------------------------------
    Public Class TestClass

    Public NextSubIndex As Integer = 1

    Public arrTestSubClass() As TestSubClass

    Public tmpHold As TestSubClass

    Sub AddSub(ByVal Name As String)

    tmpHold = New TestSubClass(Name)

    Me.arrTestSubClass(NextSubIndex) = tmpHold <<<<Error Here>>>

    NextSubIndex = NextSubIndex + 1

    End Sub

    End Class

    ----------------------------------------------------------------------------
    ------------------------------------------

    Can someone tell me why I'm getting the NullReferenceException when this
    code executes? Stack Trace and more below.

    Thank You!

    Scott

    Exception Details: System.NullReferenceException: Object reference not set
    to an instance of an object.

    Source Error:

    Line 68:
    Line 69: Private Sub btnAddSub_Click(ByVal sender As System.Object,
    ByVal e As System.EventArgs) Handles btnAddSub.Click
    Line 70: Session("MyTestClass").AddSub(TextBox2.Text)
    Line 71: End Sub
    Line 72:

    Source File: c:\inetpub\wwwroot\ASPTests\TestClassClient.aspx.v b Line: 70

    Stack Trace:

    [NullReferenceException: Object reference not set to an instance of an
    object.]

    Microsoft.VisualBasic.CompilerServices.LateBinding .InternalLateCall(Object
    o, Type objType, String name, Object[] args, String[] paramnames, Boolean[]
    CopyBack, Boolean IgnoreReturn)
    Microsoft.VisualBasic.CompilerServices.LateBinding .LateCall(Object o,
    Type objType, String name, Object[] args, String[] paramnames, Boolean[]
    CopyBack)
    ASPTests.TestClassClient.btnAddSub_Click(Object sender, EventArgs e) in
    c:\inetpub\wwwroot\ASPTests\TestClassClient.aspx.v b:70
    System.Web.UI.WebControls.Button.OnClick(EventArgs e)

    System.Web.UI.WebControls.Button.System.Web.UI.IPo stBackEventHandler.RaisePo
    stBackEvent(String eventArgument)
    System.Web.UI.Page.RaisePostBackEvent(IPostBackEve ntHandler
    sourceControl, String eventArgument)
    System.Web.UI.Page.RaisePostBackEvent(NameValueCol lection postData)
    System.Web.UI.Page.ProcessRequestMain()



    msnews.microsoft.com Guest

  2. Similar Questions and Discussions

    1. LoadPostData NullReferenceException
      I have a webcontrol which renders a select | option html control. I have implemented IPostBackDataHandler with LoadPostData looking like this: ...
    2. nullreferenceexception
      I'm having a hard time debugging a nullreferenceexception in my datagrid -- the exception occurs in 'System' .. so its hard to debug.. i can't...
    3. [WebMethod] System.NullReferenceException: Object reference not set to an instance of an object.
      Um, this isn't going to work, generally. Web services, as any web app (especially on Windows server 2003) are heavily sandboxed. The method you...
    4. Exception Details: System.NullReferenceException: Object reference not set
      Hey folks, Wow... After only 4 hours... I figured out the Index out of range error and now have run into the error below ... Any help would be...
    5. Help Me~~My DropDownList Can not get the"BigClassList.SelectedItem.Text" there is an error: System.NullReferenceException
      I have many dropdownlist controls in my ascx (and use LoadControl in a aspx fiel) file,so i write a method "InitList(DropDownList list,string...
  3. #2

    Default Re: Help with System.NullReferenceException

    That was it!

    Thanks!

    Scott

    "Natty Gur" <natty@dao2com.com> wrote in message
    news:OWjkiu0SDHA.1920@TK2MSFTNGP11.phx.gbl...
    > Hi,
    > you didnt initialize[1] your array.
    >
    > Public arrTestSubClass(2) As TestSubClass
    >
    >
    > [1 - MSDN] Initializing Arrays
    > You can initialize an array variable as part of its declaration. You can
    > do one of the following in the declaration statement:
    >
    > Specify the initial length of one or more of the dimensions in the
    > parentheses following the variable name, without assigning an array
    > object to the variable.
    > Assign an array object to the variable, using the New clause. When you
    > use a New clause, you must follow it with braces ({}), even if they are
    > empty.
    > Assign an array object to the variable and supply initial lengths in the
    > New clause.
    > Assign an array object to the variable and supply initial element values
    > in the New clause. You can supply both lengths and values in the same
    > New clause.
    >
    >
    > Natty Gur, CTO
    > Dao2Com Ltd.
    > 28th Baruch Hirsch st. Bnei-Brak
    > Israel , 51114
    >
    > Phone Numbers:
    > Office: +972-(0)3-5786668
    > Fax: +972-(0)3-5703475
    > Mobile: +972-(0)58-888377
    >
    > Know the overall picture
    >
    >
    > *** Sent via Developersdex [url]http://www.developersdex.com[/url] ***
    > Don't just participate in USENET...get rewarded for it!

    msnews.microsoft.com Guest

Posting Permissions

  • You may not post new threads
  • You may post replies
  • You may not post attachments
  • You may not edit your posts

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139