[02/03] Object reference not set to an instance of an object Error
Hi... I am getting the following error:
Quote:
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)
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
Re: [02/03] Object reference not set to an instance of an object Error
Quote:
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?
Re: [02/03] Object reference not set to an instance of an object Error
Quote:
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
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)