I'm trying to fill an array of objects but when I add the first object I get
a NullReferenceEx ception.
----------------------------------------------------------------------------
-------------------------------------------
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(Na me)
Me.arrTestSubCl ass(NextSubInde x) = tmpHold <<<<Error Here>>>
NextSubIndex = NextSubIndex + 1
End Sub
End Class
----------------------------------------------------------------------------
------------------------------------------
Can someone tell me why I'm getting the NullReferenceEx ception when this
code executes? Stack Trace and more below.
Thank You!
Scott
Exception Details: System.NullRefe renceException: 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.EventArg s) Handles btnAddSub.Click
Line 70: Session("MyTest Class").AddSub( TextBox2.Text)
Line 71: End Sub
Line 72:
Source File: c:\inetpub\wwwr oot\ASPTests\Te stClassClient.a spx.vb Line: 70
Stack Trace:
[NullReferenceEx ception: Object reference not set to an instance of an
object.]
Microsoft.Visua lBasic.Compiler Services.LateBi nding.InternalL ateCall(Object
o, Type objType, String name, Object[] args, String[] paramnames, Boolean[]
CopyBack, Boolean IgnoreReturn)
Microsoft.Visua lBasic.Compiler Services.LateBi nding.LateCall( Object o,
Type objType, String name, Object[] args, String[] paramnames, Boolean[]
CopyBack)
ASPTests.TestCl assClient.btnAd dSub_Click(Obje ct sender, EventArgs e) in
c:\inetpub\wwwr oot\ASPTests\Te stClassClient.a spx.vb:70
System.Web.UI.W ebControls.Butt on.OnClick(Even tArgs e)
System.Web.UI.W ebControls.Butt on.System.Web.U I.IPostBackEven tHandler.RaiseP o
stBackEvent(Str ing eventArgument)
System.Web.UI.P age.RaisePostBa ckEvent(IPostBa ckEventHandler
sourceControl, String eventArgument)
System.Web.UI.P age.RaisePostBa ckEvent(NameVal ueCollection postData)
System.Web.UI.P age.ProcessRequ estMain() 1 4093
That was it!
Thanks!
Scott
"Natty Gur" <na***@dao2com. com> wrote in message
news:OW******** ******@TK2MSFTN GP11.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 http://www.developersdex.com *** Don't just participate in USENET...get rewarded for it! This thread has been closed and replies have been disabled. Please start a new discussion. Similar topics |
by: Terrence |
last post by:
I am doing some of the C# walkthroughs to transition from
VB to C#. When I try to execute
static void Main()
{
Aplication.Run(new Form1())
}
I raise a 'System.NullReferenceException" in
system.windows.forms.dll
|
by: Ghada Ayed via DotNetMonster.com |
last post by:
Hello every body,
please help me in this problem
i have written the following C# code in VS.Net and when i run the window
application i have got 'System.NullReferenceException' so please if
anybody can help reply to this message.
portion of the Code
static void Main()
|
by: Raed Sawalha |
last post by:
i have a windows form(Main) with listview, when click an item in listview i
open other window form (Sub) which generate the selected item from parent
window in as treeview items when click any item in treeview i display the
content item in axWebBrowser, i close the sub form normally when i close the
main the following error is generated
An unhandled exception of type 'System.NullReferenceException' occurred in
system.windows.forms.dll
...
|
by: noe |
last post by:
I have done a DLL in unmanaged code C++ and in that dll I have defined
a function that use memcpy.This dll run ok.I use that dll in a
aplication in C# managed code in Visual Studio .NET. I import the
functions defined in the dll using DllImport and I have verified that
when in my dll I use memcpy then I have one error
:"System.NullReferenceException", and I don't known what happen?and I
must use memcpy in my dll.
Below is the definition...
|
by: muralidharan |
last post by:
WebForm1.aspx Code:
<%@ Register TagPrefix="ComponentArt" Namespace="ComponentArt.Web.UI"
Assembly="ComponentArt.Web.UI" %> <ComponentArt:TreeView
id="TreeView1" Height="520" AutoPostBackOnNodeMove="false"
DragAndDropEnabled="true"
NodeEditingEnabled="False" KeyboardEnabled="true"
CssClass="TreeView" NodeCssClass="TreeNode"
SelectedNodeCssClass="SelectedTreeNode"
HoverNodeCssClass="HoverTreeNode" NodeEditCssClass="NodeEdit"
| |
by: sxiao |
last post by:
Hi, there
I got a NullReferenceException when there are more than one users
trying to open the same page at the same time. The senerio is:
Two users logged into the web application using the Windows domain user
account and tried to open the same page which has the databasde query
code. When the two user tried to open the same page at the same time,
there is a runtime error messsage showing as follows:
|
by: William Mild |
last post by:
I must be getting brain fried. I can't see the error.
Create a new web form with the following code begind:
Public Class test
Inherits System.Web.UI.Page
Public Class ReportCardData
Public Structure Attend
Dim DaysTardy As Double
|
by: KenLee |
last post by:
I made an application which includes classic asp page and asp.net page.
when I tried to redirect from classic asp page to asp.net 2.0 page, it works
under my local IIS directory.
ex)
<a href="default.aspx?store=<%=rs("store")%>"><%=rs("store")%></a>
However, When I copy that application into one of IIS directory in another
intranet server, it doesn't work.
|
by: hcaptech |
last post by:
This is my Test.can you help me ?
1.Which of the following statement about C# varialble is incorrect ?
A.A variable is a computer memory location identified by a unique name
B.A variable's name is used to access and read the value stored in it
C.A variable is allocated or deallocated in memory during runtime
D.A variable can be initialized at the time of its creation or later
2. The.……types feature facilitates the definition of classes...
|
by: Oralloy |
last post by:
Hello folks,
I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>".
The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed.
This is as boiled down as I can make it.
Here is my compilation command:
g++-12 -std=c++20 -Wnarrowing bit_field.cpp
Here is the code in...
|
by: jinu1996 |
last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth.
The Art of Business Website Design
Your website is...
| |
by: tracyyun |
last post by:
Dear forum friends,
With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
|
by: agi2029 |
last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own....
Now, this would greatly impact the work of software developers. The idea...
|
by: TSSRALBI |
last post by:
Hello
I'm a network technician in training and I need your help.
I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs.
The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols.
I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
|
by: adsilva |
last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
|
by: 6302768590 |
last post by:
Hai team
i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
|
by: muto222 |
last post by:
How can i add a mobile payment intergratation into php mysql website.
| |
by: bsmnconsultancy |
last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...
| |