473,386 Members | 1,790 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,386 software developers and data experts.

Object Array Error

I'm trying to create a FileSystemWatcher Array, however I am new at C#... I
know its not instanciating form somereason or not getting the reference
because I'm getting the
System.NullReferenceException and Here is bascially what I have for my code:

FileSystemWatcher[] watcher = new FileSystemWatcher[2];
watcher[0].Path = "\\\\pumptest-a\\pats\\results";

This throws the exception
Nov 15 '05 #1
2 1311
Ryan,

When you create an array of reference types, it only creates space for
the references. By default, references are set to null. To fix this, you
have to create an instance and assign it to the array, like this:

watcher[0] = new FileSystemWatcher();

This will create an instance of the file system watcher and place the
reference into the array.

Hope this helps.

--
- Nicholas Paldino [.NET/C# MVP]
- mv*@spam.guard.caspershouse.com

"Ryan Rogers" <ry*********@tesma.com> wrote in message
news:ea*************@TK2MSFTNGP11.phx.gbl...
I'm trying to create a FileSystemWatcher Array, however I am new at C#... I know its not instanciating form somereason or not getting the reference
because I'm getting the
System.NullReferenceException and Here is bascially what I have for my code:
FileSystemWatcher[] watcher = new FileSystemWatcher[2];
watcher[0].Path = "\\\\pumptest-a\\pats\\results";

This throws the exception

Nov 15 '05 #2
Nicholas,
Thank you, got it working now!.. You don't by chance know anything about the
FileSystemWatcher Class do you??

I am wondering if it can accept multiple filters in it's filter property.
Eg.. *.f**;*.p** my work around right now is just using an if statment in
the event that is triggered and dropping any files there.. I would rather
have the FilesystemWatcher do it if it is capable.

Cheers,

"Nicholas Paldino [.NET/C# MVP]" <mv*@spam.guard.caspershouse.com> wrote in
message news:Ok**************@TK2MSFTNGP09.phx.gbl...
Ryan,

When you create an array of reference types, it only creates space for
the references. By default, references are set to null. To fix this, you
have to create an instance and assign it to the array, like this:

watcher[0] = new FileSystemWatcher();

This will create an instance of the file system watcher and place the
reference into the array.

Hope this helps.

--
- Nicholas Paldino [.NET/C# MVP]
- mv*@spam.guard.caspershouse.com

"Ryan Rogers" <ry*********@tesma.com> wrote in message
news:ea*************@TK2MSFTNGP11.phx.gbl...
I'm trying to create a FileSystemWatcher Array, however I am new at
C#... I
know its not instanciating form somereason or not getting the reference
because I'm getting the
System.NullReferenceException and Here is bascially what I have for my

code:

FileSystemWatcher[] watcher = new FileSystemWatcher[2];
watcher[0].Path = "\\\\pumptest-a\\pats\\results";

This throws the exception


Nov 15 '05 #3

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

6
by: lawrence | last post by:
How dangerous or stupid is it for an object to have a reference to the object which contains it? If I have a class called $controllerForAll which has an arrray of all the objects that exist, what...
4
by: lawrence | last post by:
I'm nervous this method is not doing what I assumed it was doing. Does it not create objects, store them in an array, and check that array to see if a requested class has already been instantiated,...
2
by: Asad Khan | last post by:
Hello, I am writing a method that returns an array as an Object. Initially there is a single dimension array Object X. However, I can insert other arrays as Objects in X, thus I can end up with...
54
by: tshad | last post by:
I have a function: function SalaryDisplay(me) { var salaryMinLabel = document.getElementById("SalaryMin"); salaryMinLabel.value = 200; alert("after setting salaryMinLabel = " +...
16
by: sneill | last post by:
How is it possible to take the value of a variable (in this case, MODE_CREATE, MODE_UPDATE, etc) and use that as an object property name? In the following example I want 'oIcon' object to have...
4
by: Fabrizio | last post by:
Hi I cannot figure why it isn't possible to cast a struct array to an object array. I written a structure like this: public struct Test { private int TestA; private int TestB;
9
by: Ben | last post by:
Hello, I'm not a developper, so sorry if it's a stupid question... I'm trying to develop an application in vb.net and I have the following problem: I have some information in an array:...
4
by: gg9h0st | last post by:
i'm a newbie studying php. i was into array part on tutorial and it says i'll get an array having keys that from member variable's name by converting an object to array. i guessed "i can...
3
by: klaritydefect | last post by:
Hi, I am receving the following error when I run my application (build on C ++ code) Program received signal SIGSEGV, Segmentation fault si_code: 1 - SEGV_MAPERR - Address not mapped to...
14
by: chromis | last post by:
Hi, I've been trying to implement a more OOP oriented approach to dealing with user security on one of my websites, and I am trying to validate the user against an array of roles, however I am...
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.