Despite last nights extreme anger over the fact that I thought I was going to redo the structure of my Fizzure application, I learned today that I most likely do not! And this simple fact makes me very happy. There is almost nothing I hate more than having to redo work.
I came into school this morning with some of my code in hand and went straight to my computer science room. My teacher (the ever brilliant Dianne Meskauskas) took a quick look at my code. As it turns out I had just made a small mistake of where I had placed the creation of one of my objects.
The error I kept getting was a NullObjectException when I tried to access an array. I had made the creation of the object inside of a timer, so each time the timer ticked, it was creating a new object. On the first time it ticks, it creates the object “o” of the OptionControl class and fills the array SharedDirectories. On the second tick, it recreates “o” and tries to access the now empty array SharedDirectories, thus giving me the NullObjectException
Here is the little code snippet :
private void timer1_Tick(object sender, EventArgs e) {
OptionControl o = new OptionControl();
if (count == 0) {
loadWhat.Text = "Finding Shared Directories...";
o.SharedDirectories = o.getSharedDirs();
} else if (count == 1) {
loadWhat.Text = "Scanning Directories...";
o.DoScan();
} else if (count == 2) {
loadWhat.Text = "Shared Directories Found!";
} else {
Dispose(false);
}
count += 1;
}
My mistake here is on the first line. This line needs to be taken out of there and made as a class variable instead of inside a method, that way it can be accessed from any of the methods and have the same data as well.