|
-
Jul 11th, 2007, 09:40 AM
#1
Thread Starter
Lively Member
[02/03] Object reference not set to an instance of an object Error
Hi... I am getting the following error:
An unhandled exception of type 'System.NullReferenceException' occurred in system.windows.forms.dll
Additional information: Object reference not set to an instance of an object.
I am trying to copy a listview collection to an array. I want the array to be string but then I get another error if I try to copy listview.items to a string array
Code:
Dim sourceArray() As Object
frm1.lstRight.Items.CopyTo(sourceArray, 0)
-
Jul 11th, 2007, 09:47 AM
#2
Re: [02/03] Object reference not set to an instance of an object Error
You have to set/specify the size of the Object array first of all. You might be able to do something like this:
vb Code:
Dim sourceArray(Me.ListView1.Items.Count -1) As Object 'Creates correct size of array
-
Jul 11th, 2007, 10:16 AM
#3
Re: [02/03] Object reference not set to an instance of an object Error
 Originally Posted by jeffnyc
Code:
frm1.lstRight.Items.CopyTo(sourceArray, 0)
Is frm1 the actual name of the form, or the current instance? If frm1 is the name of the form then that is your problem. Also, is this the line that throws the error?
-
Jul 11th, 2007, 10:46 AM
#4
Thread Starter
Lively Member
Re: [02/03] Object reference not set to an instance of an object Error
 Originally Posted by circuits2
Is frm1 the actual name of the form, or the current instance? If frm1 is the name of the form then that is your problem. Also, is this the line that throws the error?
frm1 is the instance, i believe... fm1 is declared in a module and when form1 loads frm1 = me
i believe it is the way i am copying listview collection of objects to a standard array and in the way i declare it -
haven't tried stimbo's suggestion but also wondering if i need the NEW keyword anywhere
-
Jul 11th, 2007, 10:57 AM
#5
Re: [02/03] Object reference not set to an instance of an object Error
Ok, you need to change it to this:
Me.lstRight.Items.CopyTo(sourceArray, 0)
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
|