|
-
Mar 17th, 2005, 05:19 AM
#1
Thread Starter
PowerPoster
wierd error!
Hi there.
I am trying to copy a value into a string array.
However, it is not liking it - throwing me an "object reference is null" exception...
now, the wierd thing is, almost the same line(s) of code work in another class in this project, but when i try to do it in a different class, this error occurs!
the source from where i am trying to copy the value from, does have something in it. this is what im doing:
Code:
Dim theStringArray() as string
for x = 0 to someOtherArrayList.count - 1
theStringArray(x) = someOtherArrayList(x).ToString() 'i have tried without the ToString()
next
?? whats the prob?
-
Mar 17th, 2005, 05:38 AM
#2
Hyperactive Member
Re: wierd error!
It looks to me like the actual object in the someOtherArrayList(x) doesn't have anything in it. The object has been created but not instantiated.
Where are you getting the data from? Is it definitely populating that array correctly?
Be who you are and say what you feel, because those who mind don't matter and those who matter don't mind.
Dr. Seuss 
-
Mar 17th, 2005, 05:48 AM
#3
Thread Starter
PowerPoster
Re: wierd error!
but it does! I have debugged it, and objects exist
-
Mar 17th, 2005, 05:49 AM
#4
Hyperactive Member
Re: wierd error!
not sure about it, base on your code given, but try.
VB Code:
Dim theStringArray() as string
for x = 0 to someOtherArrayList.count - 1
ReDim Preserve theStringArray(x)
theStringArray(x) = someOtherArrayList(x).ToString() 'i have tried without the ToString()
next
-
Mar 17th, 2005, 06:10 AM
#5
Re: wierd error!
You have not initialized the array. It is just a null reference. The object does NOT exist yet .
Use:
VB Code:
Dim theStringArray() as string = New String(NUM) {}
Where NUM is the upper bound of the array (if you want 10 elements then NUM = 9)
I don't live here any more.
-
Mar 17th, 2005, 06:11 AM
#6
Re: wierd error!
Do NOT use this...
 Originally Posted by fret
not sure about it, base on your code given, but try.
VB Code:
Dim theStringArray() as string
for x = 0 to someOtherArrayList.count - 1
ReDim Preserve theStringArray(x)
theStringArray(x) = someOtherArrayList(x).ToString() 'i have tried without the ToString()
next
Redimming everytime will ruin performance and it is totally unneccesary.
I don't live here any more.
-
Mar 17th, 2005, 06:21 AM
#7
Re: wierd error!
However you never said which object reference was causing the error.
(Hover your mouse over the code when the app is paused and it will say "BlahBlah = Nothing" if the reference is null.
It could be the other arraylist thats not been properly filled.
I don't live here any more.
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|