-
October 4th, 2018, 10:37 PM
#1
List.Add not set to an instance of an object
Hi, I've got a method where I'm trying to add an object to a list, and Visual Studio debug gives me an error that what I'm trying to add is "not set to an instance of an object". I set my list to be List(Of Object), and also set my variable to a FileSystemWatcher object, but still get the error. Breakpoint just tells me the same thing. Here's my code...if someone has any ideas why I'm getting this error I'm open to suggestions. I've also tried setting everything to string type, but still get the same debug message. Here's my code:
Code:
Public FSWList As List(Of Object)
Public Sub SetupFileWatcher(fswPath As String, fswPlan As String, fswFilter As String, SyncObject As Form)
Dim fsw As FileSystemWatcher = New FileSystemWatcher(fswPath)
If fswPath.Length = 0 Then
Return
End If
fsw.BeginInit()
fsw.SynchronizingObject = SyncObject
fsw.InternalBufferSize = 32768
fsw.IncludeSubdirectories = True
fsw.Filter = fswFilter
fsw.Path = fswPath
fsw.NotifyFilter = NotifyFilters.FileName Or NotifyFilters.CreationTime
AddHandler Me.Created, New FileSystemEventHandler(AddressOf Me.OnCreated)
AddHandler Me.Deleted, New FileSystemEventHandler(AddressOf Me.OnDeleted)
fsw.EnableRaisingEvents = True
fsw.EndInit()
'this is the line that is giving me the error
FSWList.Add(fsw)
End Sub
Thanks for any ideas.
-
October 5th, 2018, 01:31 AM
#2
Re: List.Add not set to an instance of an object
It's not initialized. Initialize it with New in the class constructor.
-
October 5th, 2018, 03:03 AM
#3
Re: List.Add not set to an instance of an object
You'll need to ensure that the collection isn't null and is properly instantiated prior to adding an object to it.
gmail sign up
-
October 5th, 2018, 10:15 PM
#4
Re: List.Add not set to an instance of an object
Thanks y'all, that was exactly the problem. It never ceases to amaze me how basic things like that make the difference. Hey Arjay, I don't know if that code I posted was good for you to review on our discussion of binding. If you still want me to make a solution for you to look at before we continue, let me know. I searched on the net for some material about it, but didn't find anything. Wasn't really sure of what I was looking for. The book I've got on Visual Studio talks about collections in general, but still leaves a lot to be learned.
Appreciate the input folks...
Tags for this Thread
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
|