Connecting Tech Pros Worldwide Help | Site Map

Object referense not set to instance error

  #1  
Old November 20th, 2005, 03:26 AM
Stephen
Guest
 
Posts: n/a
I hate this error and usually can find a way to fix it but this one has me
stumped

tColors is an ArrayList

At first I had this:

tColors.Add(ColorsTextBox.Text)

Now I have this:

Dim str As String
str = ColorsTextBox.Text
tColors.Add(str)

Neither one works and both give me the "Object reference not set to an
instance of an object" error. How is str NOT an instance of an object?? It
is clearly defined right above.


  #2  
Old November 20th, 2005, 03:26 AM
Brian
Guest
 
Posts: n/a

re: Object referense not set to instance error


Did you use NEW to declare your array list? Your code worked perfectly when
I tried it.

Dim tColors as New ArrayList()





"Stephen" <graybeal@bellatlantic.net> wrote in message
news:%23pUKZQWiDHA.2380@tk2msftngp13.phx.gbl...[color=blue]
> I hate this error and usually can find a way to fix it but this one has me
> stumped
>
> tColors is an ArrayList
>
> At first I had this:
>
> tColors.Add(ColorsTextBox.Text)
>
> Now I have this:
>
> Dim str As String
> str = ColorsTextBox.Text
> tColors.Add(str)
>
> Neither one works and both give me the "Object reference not set to an
> instance of an object" error. How is str NOT an instance of an object??[/color]
It[color=blue]
> is clearly defined right above.
>
>[/color]


  #3  
Old November 20th, 2005, 03:26 AM
Herfried K. Wagner [MVP]
Guest
 
Posts: n/a

re: Object referense not set to instance error


"Stephen" <graybeal@bellatlantic.net> scripsit:[color=blue]
> tColors is an ArrayList
>
> At first I had this:
>
> tColors.Add(ColorsTextBox.Text)
>
> Now I have this:
>
> Dim str As String
> str = ColorsTextBox.Text
> tColors.Add(str)
>
> Neither one works and both give me the "Object reference not set to an
> instance of an object" error. How is str NOT an instance of an object?? It
> is clearly defined right above.[/color]

I think the problem is that 'ColorsTextBox' is pointing to 'Nothing'.
Where do you use this code?

--
Herfried K. Wagner
MVP · VB Classic, VB.NET
<http://www.mvps.org/dotnet>
  #4  
Old November 20th, 2005, 03:27 AM
Fergus Cooney
Guest
 
Posts: n/a

re: Object referense not set to instance error


Hi Stephen,

Sherlock Holmes:
When you have eliminated the impossible,
whatever remains - however improbable -
<must> be the truth.

You've eliminated str.

;-)

Regards,
Fergus


  #5  
Old November 20th, 2005, 03:27 AM
Stephen
Guest
 
Posts: n/a

re: Object referense not set to instance error


I don't know why, but that worked. I've been programming in VB for years
and never really understood the difference between a declaration with and
without New.

Thanks.

"Brian" <nospam@prairie.lakes.com> wrote in message
news:vnpuuo2bjeih94@corp.supernews.com...[color=blue]
> Did you use NEW to declare your array list? Your code worked perfectly[/color]
when[color=blue]
> I tried it.
>
> Dim tColors as New ArrayList()
>
>
>
>
>
> "Stephen" <graybeal@bellatlantic.net> wrote in message
> news:%23pUKZQWiDHA.2380@tk2msftngp13.phx.gbl...[color=green]
> > I hate this error and usually can find a way to fix it but this one has[/color][/color]
me[color=blue][color=green]
> > stumped
> >
> > tColors is an ArrayList
> >
> > At first I had this:
> >
> > tColors.Add(ColorsTextBox.Text)
> >
> > Now I have this:
> >
> > Dim str As String
> > str = ColorsTextBox.Text
> > tColors.Add(str)
> >
> > Neither one works and both give me the "Object reference not set to an
> > instance of an object" error. How is str NOT an instance of an object??[/color]
> It[color=green]
> > is clearly defined right above.
> >
> >[/color]
>
>[/color]


Closed Thread


Similar Threads
Thread Thread Starter Forum Replies Last Post
An unhandled exception of type 'System.NullReferenceException' occurred juli answers 3 November 16th, 2005 06:52 PM