Object not set to an Instance of an Object

Discussion in 'C#' started by dumbestcrayon, Sep 7, 2010.

  1. dumbestcrayon

    dumbestcrayon New Member

    Joined:
    Sep 7, 2010
    Messages:
    1
    Likes Received:
    0
    Trophy Points:
    0
    Okay, My program gathers the drive information of the mounted drives and sets one of them as the location to save their information. For some reason I'm not getting any error while debugging but almost everybody gets an error when I publish the program. Here is the error I get followed by the lines of code where the error occurs. I am not seeing where I haven't set an Object as an instance. Many thanks in advance for the help..


    :::Error:::
    Code:
    Method: Void setPersonalDrive()
    Object reference not set to an instance of an object.
       at U_Notes_V3.MainWindow.setPersonalDrive()
       at U_Notes_V3.MainWindow.Form1_Load(Object sender, EventArgs e)
       at System.Windows.Forms.Form.OnLoad(EventArgs e)
       at System.Windows.Forms.Form.OnCreateControl()
       at System.Windows.Forms.Control.CreateControl(Boolean fIgnoreVisible)
       at System.Windows.Forms.Control.CreateControl()
       at System.Windows.Forms.Control.WmShowWindow(Message& m)
       at System.Windows.Forms.Control.WndProc(Message& m)
       at System.Windows.Forms.ScrollableControl.WndProc(Message& m)
       at System.Windows.Forms.ContainerControl.WndProc(Message& m)
       at System.Windows.Forms.Form.WmShowWindow(Message& m)
       at System.Windows.Forms.Form.WndProc(Message& m)
       at System.Windows.Forms.Control.ControlNativeWindow.OnMessage(Message& m)
       at System.Windows.Forms.Control.ControlNativeWindow.WndProc(Message& m)
       at System.Windows.Forms.NativeWindow.Callback(IntPtr hWnd, Int32 msg, IntPtr wparam, IntPtr lparam)
    
    :::Code:::
    Code:
    private void setPersonalDrive()
            {
                DriveInfo[] drives = DriveInfo.GetDrives();
                DriveInfo storeDrive = new DriveInfo("C");
    
                try
                {
                    storeDrive = getPersonalDriveInfo(drives);
                }
                catch
                {
                    storeDrive = getLsDriveInfo(drives);
                }
                
    
                Settings.Default.logStoreLocation = storeDrive.RootDirectory.ToString();
    
                if (storeDrive.TotalSize != 4294967296)
                {
                    Settings.Default.logStoreLocation = storeDrive.RootDirectory.ToString() 
                        + SystemInformation.UserName.ToLower().Trim() + "\\";
    
                    if (!Directory.Exists(Settings.Default.logStoreLocation))
                    {
                        try
                        {
                            Directory.CreateDirectory(Settings.Default.logStoreLocation);
                        }
                        catch (Exception)
                        {
                            MessageBox.Show("U-notes was unable to create your log directory.\n" +
                                "Please contact bj2356 immediately with this information");
    
                        }
    
                    }
                }
                else if (storeDrive.TotalSize == 4294967296)
                {
                    Settings.Default.logStoreLocation = storeDrive.RootDirectory.ToString();
                }
                
            }
    
            private DriveInfo getPersonalDriveInfo(DriveInfo[] drives)
            {
                for (int i = 0; i < drives.Length; i++)
                {
                    if (drives[i].IsReady)
                    {
                        if (drives[i].TotalSize == 4294967296)
                        {
                            return drives[i];
                            
                        }
                    }
                }
                return null;
            }
    
            private DriveInfo getLsDriveInfo(DriveInfo[] drives)
            {
                for (int i = 0; i < drives.Length; i++)
                {
                    if (drives[i].IsReady)
                    {
                        if (drives[i].VolumeLabel.ToLower().Contains("txdlls2cdfile02"))
                        {
                            return drives[i];
    
                        }
                    }
                }
                return null;
            }
     

Share This Page

  1. This site uses cookies to help personalise content, tailor your experience and to keep you logged in if you register.
    By continuing to use this site, you are consenting to our use of cookies.
    Dismiss Notice