Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > ASP .Net > Help with System.NullReferenceException

Reply
Thread Tools

Help with System.NullReferenceException

 
 
msnews.microsoft.com
Guest
Posts: n/a
 
      07-16-2003
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()



 
Reply With Quote
 
 
 
 
msnews.microsoft.com
Guest
Posts: n/a
 
      07-16-2003
That was it!

Thanks!

Scott

"Natty Gur" <(E-Mail Removed)> wrote in message
news:(E-Mail Removed)...
> 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 http://www.developersdex.com ***
> Don't just participate in USENET...get rewarded for it!



 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Help Help Help Pentax S5i Help needed (Please) The Martian Digital Photography 14 06-20-2008 07:56 AM
HELP - HELP - HELP =?Utf-8?B?S2ltb24gSWZhbnRpZGlz?= ASP .Net 4 03-09-2006 12:46 PM
HELP WANTED HELP WANTED HELP WANTED Harvey ASP .Net 1 07-16-2004 01:12 PM
HELP WANTED HELP WANTED HELP WANTED Harvey ASP .Net 0 07-16-2004 10:00 AM
HELP! HELP! HELP! Opening Web Application Project Error =?Utf-8?B?dHJlbGxvdzQyMg==?= ASP .Net 0 02-20-2004 05:16 PM



Advertisments