473,386 Members | 1,710 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,386 software developers and data experts.

Array problem with custom class

I have an array declared as follows:

Dim ButtonList() As NavButtonInfo

and a Class defined as follows:

Public Class NavButtonInfo

Public Shared name As String

Public Shared text As String

Public Shared URL As String

Public Shared parentname As String

Public Shared Sub SetButtonInfo(ByVal name As String, ByVal text As
String, ByVal URL As String, ByVal parentname As String)

NavButtonInfo.name = name

NavButtonInfo.text = text

NavButtonInfo.URL = URL

NavButtonInfo.parentname = parentname

End Sub

End Class
I am adding data to my array using the following code:

ButtonList(0).SetButtonInfo("homeindex", "Life With Nate", "/index.aspx",
Nothing)
When I build and run my application, I recieve an error that tells me the
following:

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

I think I must be doing something wrong or forgetting something when I add
data to the array, but I am not sure what. Can anyone tell me what I am
forgetting? Thanks.
--
Nathan Sokalski
nj********@hotmail.com
http://www.nathansokalski.com/
Nov 19 '05 #1
3 1348
you are declaring the array but never instantiating instances of it..

dim ButtonList(10) as NavButtonInfo

ButtonList(0) = new NavButtonInfo
ButtonList(0).SetButtonInfo(...)

seems though like SetButtonInfo should be your custructor instead so that
you can do:

ButtonList(0) = new NavButtonInfo("homeindex", "Life With Nate",
"/index.aspx", Nothing)

If you don't know the size of the Array consider using an ArrayList.
Karl

--
MY ASP.Net tutorials
http://www.openmymind.net/ - New and Improved (yes, the popup is annoying)
http://www.openmymind.net/faq.aspx - unofficial newsgroup FAQ (more to
come!)
"Nathan Sokalski" <nj********@hotmail.com> wrote in message
news:OV***************@TK2MSFTNGP10.phx.gbl...
I have an array declared as follows:

Dim ButtonList() As NavButtonInfo

and a Class defined as follows:

Public Class NavButtonInfo

Public Shared name As String

Public Shared text As String

Public Shared URL As String

Public Shared parentname As String

Public Shared Sub SetButtonInfo(ByVal name As String, ByVal text As
String, ByVal URL As String, ByVal parentname As String)

NavButtonInfo.name = name

NavButtonInfo.text = text

NavButtonInfo.URL = URL

NavButtonInfo.parentname = parentname

End Sub

End Class
I am adding data to my array using the following code:

ButtonList(0).SetButtonInfo("homeindex", "Life With Nate", "/index.aspx",
Nothing)
When I build and run my application, I recieve an error that tells me the
following:

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

I think I must be doing something wrong or forgetting something when I add
data to the array, but I am not sure what. Can anyone tell me what I am
forgetting? Thanks.
--
Nathan Sokalski
nj********@hotmail.com
http://www.nathansokalski.com/

Nov 19 '05 #2
Thanks. And you are right, I probably should make SetButtonInfo my
constructor. The reason I didn't do that is because I don't know how (I was
never really taught how to make constructors in VB.NET). If you could give
me a simple example, I would appreciate it. Thanks.
--
Nathan Sokalski
nj********@hotmail.com
http://www.nathansokalski.com/

"Karl Seguin" <karl REMOVE @ REMOVE openmymind REMOVEMETOO . ANDME net>
wrote in message news:OM*************@TK2MSFTNGP12.phx.gbl...
you are declaring the array but never instantiating instances of it..

dim ButtonList(10) as NavButtonInfo

ButtonList(0) = new NavButtonInfo
ButtonList(0).SetButtonInfo(...)

seems though like SetButtonInfo should be your custructor instead so that
you can do:

ButtonList(0) = new NavButtonInfo("homeindex", "Life With Nate",
"/index.aspx", Nothing)

If you don't know the size of the Array consider using an ArrayList.
Karl

--
MY ASP.Net tutorials
http://www.openmymind.net/ - New and Improved (yes, the popup is annoying)
http://www.openmymind.net/faq.aspx - unofficial newsgroup FAQ (more to
come!)
"Nathan Sokalski" <nj********@hotmail.com> wrote in message
news:OV***************@TK2MSFTNGP10.phx.gbl...
I have an array declared as follows:

Dim ButtonList() As NavButtonInfo

and a Class defined as follows:

Public Class NavButtonInfo

Public Shared name As String

Public Shared text As String

Public Shared URL As String

Public Shared parentname As String

Public Shared Sub SetButtonInfo(ByVal name As String, ByVal text As
String, ByVal URL As String, ByVal parentname As String)

NavButtonInfo.name = name

NavButtonInfo.text = text

NavButtonInfo.URL = URL

NavButtonInfo.parentname = parentname

End Sub

End Class
I am adding data to my array using the following code:

ButtonList(0).SetButtonInfo("homeindex", "Life With Nate", "/index.aspx",
Nothing)
When I build and run my application, I recieve an error that tells me the
following:

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

I think I must be doing something wrong or forgetting something when I
add data to the array, but I am not sure what. Can anyone tell me what I
am forgetting? Thanks.
--
Nathan Sokalski
nj********@hotmail.com
http://www.nathansokalski.com/


Nov 19 '05 #3
Public Sub New(ByVal name As String, ByVal text As tring, ByVal URL As
String, ByVal parentname As String)
me.name = name
me.text = text
me.URL = URL
me.parentname = parentname
End Sub

I just realized your SetButtonInfo was shared, as are your public fields.
This would imply that you can ever have 1 value in them at a time...yet you
want to declare an array of them. My guess is that you don't mean for them
to be shared...but fell into the trap of making them shared one of at a time
to get it quasi-working. This is what your class should look like (unless I
misunderstand the context, which is highly likely):

Do note that changing from shared to not is a pretty big change, so you
should learn the difference between the two before blindly accepting what
I'm saying..both are legitimate, depending on what you are doing
(http://www.vbip.com/books/1861004915...er_4915_08.asp
http://www.ondotnet.com/pub/a/dotnet...rovbnetoo.html Google)

Public Class NavButtonInfo
private _name as string
private _text as string
private _url as string
private _parentName as string

public property Name As String
get
return _name
end get
set (value as string)
_name = value
end set
end property
public property Text As String
get
return _text
end get
set (value as string)
_name = value
end set
end property
public property Url As String
get
return _url
end get
set (value as string)
_url = value
end set
end property
public property ParentName As String
get
return _parentName
end get
set (value as string)
_parentName = value
end set
end property

Public Sub New(ByVal name As String, ByVal text As tring, ByVal URL As
String, ByVal parentname As String)
_name = name
_text = text
_URL = URL
_parentname = parentname
End Sub

End Class
--
MY ASP.Net tutorials
http://www.openmymind.net/ - New and Improved (yes, the popup is annoying)
http://www.openmymind.net/faq.aspx - unofficial newsgroup FAQ (more to
come!)
"Nathan Sokalski" <nj********@hotmail.com> wrote in message
news:Oh*************@tk2msftngp13.phx.gbl...
Thanks. And you are right, I probably should make SetButtonInfo my
constructor. The reason I didn't do that is because I don't know how (I
was never really taught how to make constructors in VB.NET). If you could
give me a simple example, I would appreciate it. Thanks.
--
Nathan Sokalski
nj********@hotmail.com
http://www.nathansokalski.com/

"Karl Seguin" <karl REMOVE @ REMOVE openmymind REMOVEMETOO . ANDME net>
wrote in message news:OM*************@TK2MSFTNGP12.phx.gbl...
you are declaring the array but never instantiating instances of it..

dim ButtonList(10) as NavButtonInfo

ButtonList(0) = new NavButtonInfo
ButtonList(0).SetButtonInfo(...)

seems though like SetButtonInfo should be your custructor instead so that
you can do:

ButtonList(0) = new NavButtonInfo("homeindex", "Life With Nate",
"/index.aspx", Nothing)

If you don't know the size of the Array consider using an ArrayList.
Karl

--
MY ASP.Net tutorials
http://www.openmymind.net/ - New and Improved (yes, the popup is
annoying)
http://www.openmymind.net/faq.aspx - unofficial newsgroup FAQ (more to
come!)
"Nathan Sokalski" <nj********@hotmail.com> wrote in message
news:OV***************@TK2MSFTNGP10.phx.gbl...
I have an array declared as follows:

Dim ButtonList() As NavButtonInfo

and a Class defined as follows:

Public Class NavButtonInfo

Public Shared name As String

Public Shared text As String

Public Shared URL As String

Public Shared parentname As String

Public Shared Sub SetButtonInfo(ByVal name As String, ByVal text As
String, ByVal URL As String, ByVal parentname As String)

NavButtonInfo.name = name

NavButtonInfo.text = text

NavButtonInfo.URL = URL

NavButtonInfo.parentname = parentname

End Sub

End Class
I am adding data to my array using the following code:

ButtonList(0).SetButtonInfo("homeindex", "Life With Nate",
"/index.aspx", Nothing)
When I build and run my application, I recieve an error that tells me
the following:

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

I think I must be doing something wrong or forgetting something when I
add data to the array, but I am not sure what. Can anyone tell me what I
am forgetting? Thanks.
--
Nathan Sokalski
nj********@hotmail.com
http://www.nathansokalski.com/



Nov 19 '05 #4

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

7
by: Federico G. Babelis | last post by:
Hi All: I have this line of code, but the syntax check in VB.NET 2003 and also in VB.NET 2005 Beta 2 shows as unknown: Dim local4 As Byte Fixed(local4 = AddressOf dest(offset)) ...
1
by: parrot toes | last post by:
I tried to post this question before, but there was an error when posting. I case it did get posted and in order to avoid duplication, I'll just repost a summary. I have written a dotnet client...
7
by: John Grandy | last post by:
My ASP.NET Web Service project has a Web Method that returns an array filled with instances of a custom class. The custom class is defined in a Class Library that is included in the web-service...
18
by: Sam | last post by:
Hi All I'm planing to write an application which allows users dynamically add their points (say you can add upto 30,000) and then draw xy graph. Should I use an array for my coordinate point...
9
by: mupe | last post by:
Hi, i have a problem with a Type Library, which is written in C++. I am developing an application in C#.NET and have to use functions from this COM-Type Library. When I use these functions in...
17
by: =?Utf-8?B?U2hhcm9u?= | last post by:
Hi Gurus, I need to transfer a jagged array of byte by reference to unmanaged function, The unmanaged code should changed the values of the array, and when the unmanaged function returns I need...
6
by: djm | last post by:
hi, lets say ive this struct array in my header file public: IndepHTable(); private: struct { string word; List defList;
9
by: =?Utf-8?B?RGFya21hbg==?= | last post by:
Hi, I am wondering how you multi-dimension an array function? My declared function looks like this: Public Function GetCustomerList(ByVal Val1 As String, ByVal Val2 As Long, ByVal Val3 As...
9
by: devloop | last post by:
Hi, I am a JAVA developer who just started with php5 (on a WAMPP with php5.2.1). I´ve the following problem with a little class (I wanted to put objects into the array later but even with...
2
by: yeshello54 | last post by:
so here is my problem...in a contact manager i am trying to complete i have ran into an error..we have lots of code because we have some from class which we can use...anyways i keep getting an error...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
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,...
0
jinu1996
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...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.