Help with System.NullReferenceException

  • Thread starter msnews.microsoft.com
  • Start date
M

msnews.microsoft.com

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.vb 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.vb:70
System.Web.UI.WebControls.Button.OnClick(EventArgs e)

System.Web.UI.WebControls.Button.System.Web.UI.IPostBackEventHandler.RaisePo
stBackEvent(String eventArgument)
System.Web.UI.Page.RaisePostBackEvent(IPostBackEventHandler
sourceControl, String eventArgument)
System.Web.UI.Page.RaisePostBackEvent(NameValueCollection postData)
System.Web.UI.Page.ProcessRequestMain()
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,755
Messages
2,569,536
Members
45,020
Latest member
GenesisGai

Latest Threads

Top