"inaccessible due to protection level" error

dropper166's Avatar, Join Date: Apr 2009
Newbie Member
i got this error "inaccessible due to protection level" and do not know what it is...i have tried everything for 3 days from changing private to public to rewrote all the code but it gives same error...i just copied all some code from my books what i do not understand is my program has one error....my classmates do not know what the problem is

here is the error from :
Code:
using System; 
using System.Windows.Forms; 
using System.IO; 
using WindowsApplication2; 
 
namespace WindowsApplication2 
{ 
   public partial class SavingClass :  Form1 
   { 
      private StreamWriter fileWriter; // writes datea to text file 
      private FileStream output; // maintains connection  to file 
 
 
        //pramaterless constructor 
        public SavingClass() 
        { 
            InitializeComponent();      // <-------this line code has  blue 
                                                                 underline and shows the 
 "inaccessible due to protection level" error 
                                                                  message 
 
         }//end constructor 
......

this code is from my third class

below is the full code of my program







(Class form1)
Code:
 
using System; 
using System.Windows.Forms; 
 
namespace WindowsApplication2 
{ 
    public partial class Form1 : Form 
    { 
       protected int TextBoxCount = 5; // number of TextBoxes on Form 
 
        //enumeration constants specify textbox indices 
        public enum TextBoxIndices 
        { 
            VIDEOAUDIO, 
            TITLE, 
            CATEGORY, 
            CERTIFICATION, 
            COPIES 
        } 
 
        //parameterless constructor 
        public Form1() 
        { 
            InitializeComponent(); 
        } 
        //end constructor 
 
        //clear all TExtBoxes 
        public void ClearTextBoxes() 
        { 
            //iterate through every control on form 
            for (int i = 0; i < Controls.Count; i++) 
            { 
                Control myControl = Controls[i]; // get control 
 
                //determine wheterh control is textbox 
                if (myControl is TextBox) 
                { 
                    //clear text property (set to empty string ) 
                    myControl.Text = ""; 
                }//end if 
            }//end for 
        }//end method ClearTextBoxes 
 
        //set text box values to string array values 
        public void SetTextBoxValues(string[] values) 
        { 
            //determine wethere string array has correct lenght 
            if (values.Length != TextBoxCount) 
            { 
                //throw exception if not correct length 
                throw (new ApplicationException(" There must be " + 
                    (TextBoxCount + 1) + " string in the array")); 
            }//end if 
 
 
            //set array values if array has correct lenght 
            else 
            { 
                //seet array values to text box values 
                videoaudiocodeTextBox.Text = values[(int)TextBoxIndices.VIDEOAUDIO]; 
                titleTextBox.Text = values[(int)TextBoxIndices.TITLE]; 
                categoryTextBox.Text = values[(int)TextBoxIndices.CATEGORY]; 
                certificationTextBox.Text = values[(int)TextBoxIndices.CERTIFICATION]; 
                copiesTextBox.Text = values[(int)TextBoxIndices.COPIES]; 
            }//end else 
        }//end method SetTExtValues 
 
        //return text box values as string array 
        public string[] GetTextBoxValues() 
        { 
            string[] values = new string[TextBoxCount]; 
 
            //copy text box fields to string array 
            values[(int)TextBoxIndices.VIDEOAUDIO] = videoaudiocodeTextBox.Text; 
            values[(int)TextBoxIndices.TITLE] = titleTextBox.Text; 
            values[(int)TextBoxIndices.CATEGORY] = categoryTextBox.Text; 
            values[(int)TextBoxIndices.CERTIFICATION] = certificationTextBox.Text; 
            values[(int)TextBoxIndices.COPIES] = copiesTextBox.Text; 
 
            return values; 
        } 
 
       
        
        }//end method 
    }//end class 
 
 
 
 
 
 
 
 
 
(recordclass) 
using System; 
using System.Collections.Generic; 
using System.Text; 
 
namespace WindowsApplication2 
{ 
   public class RecordClass 
   { 
      private int videoandaudio; 
      private string title; 
      private string category; 
      private string certification; 
      private int copies; 
 
      //parameterless constructor sets members to default values 
      public RecordClass() 
         : this(0, "", "", "", 0) 
      { 
      }//end constructor 
 
      //overloaded constructor sets members to parameter values  
      public RecordClass(int videoandaudioValue, string titleValue, string categoryValue, 
          string certificationValue, int copiesValue) 
      { 
         Videoandaudio = videoandaudioValue; 
         Title = titleValue; 
         Category = categoryValue; 
         Certification = certificationValue; 
         Copies = copiesValue; 
      }//end constructor 
 
      //property that gets and sets account 
      public int Videoandaudio 
      { 
         get 
         { 
            return videoandaudio; 
         }//end get 
 
         set 
         { 
            videoandaudio = value; 
         }//endset 
      }//end property Videoandaudio 
 
      //property that gets and sets title 
      public string Title 
      { 
         get 
         { 
            return title; 
         }//end get 
 
         set 
         { 
            title = value; 
         }//endset 
      }//end property title 
 
      //property that gets and sets category 
      public string Category 
      { 
         get 
         { 
            return category; 
         }//end get 
 
         set 
         { 
            category = value; 
         }//endset 
      }//end property category 
 
      //property that gets and sets certification 
      public string Certification 
      { 
         get 
         { 
            return certification; 
         }//end get 
 
         set 
         { 
            certification = value; 
         }//endset 
      }//end property certification 
 
      //property that gets and sets coopies 
      public int Copies 
      { 
         get 
         { 
            return copies; 
         }//end get 
 
         set 
         { 
            copies = value; 
         }//endset 
      }//end property copies 
 
 
 
 
      }//end class 
   } 
 
 
 
 
 
 
 
 
 
 
(savingclass)   
using System; 
using System.Windows.Forms; 
using System.IO; 
using WindowsApplication2; 
 
namespace WindowsApplication2 
{ 
   public partial class SavingClass :  Form1 
   { 
      private StreamWriter fileWriter; // writes datea to text file 
      private FileStream output; // maintains connection  to file 
 
 
        //pramaterless constructor 
        public SavingClass() 
        { 
            InitializeComponent();    ---here is the error 
 
        }//end constructor 
 
 
        
        //event handelr for Save button 
        private void saveButton_Click(object sender, EventArgs e) 
        { 
            //create dialog box enabling uer to save file 
            SaveFileDialog fileChooser = new SaveFileDialog(); 
            DialogResult result = fileChooser.ShowDialog(); 
            string fileName; // name of file to save data 
 
            fileChooser.CheckFileExists = false; // allow user to create file 
 
            //exit event handler if user clicked "Cancel" 
            if (result == DialogResult.Cancel) 
                return; 
 
            fileName = fileChooser.FileName; // get specified file name 
 
            //show error if user specified invalid file 
            if (fileName == "" || fileName == null) 
                MessageBox.Show(" Invalid File Name", "Error", 
                    MessageBoxButtons.OK, MessageBoxIcon.Error); 
            else 
            { 
                //save file via filestream if user specified valid file 
                try 
                { 
                    //open ifle with write access 
                    output = new FileStream(fileName, 
                        FileMode.OpenOrCreate, FileAccess.Write); 
 
                    //sets file to where data is written 
                    fileWriter = new StreamWriter(output); 
 
                    //disable save button and enable enter button 
                     
                    saveButton.Enabled = false; 
                    enterButton.Enabled = true; 
                }//end try 
 
                //handle exception if ther is a problem opening the file 
                catch (IOException) 
                { 
                    //notify user if file doesnot exist 
                    MessageBox.Show("Error opening file", "error", 
                      MessageBoxButtons.OK, MessageBoxIcon.Error); 
                }//end catch 
            }//end else 
        }//end method saveButton_click 
 
        //handler for enterButton_click 
        private void enterButton_Click(object sender, EventArgs e) 
        { 
            //store Textbox values string array 
            string[] values = GetTextBoxValues(); 
 
            //record containg textbox values to serialize 
            RecordClass class1 = new RecordClass(); 
 
            //determine whether textbox account field is empty 
            if ( values [ ( int ) TextBoxIndices.VIDEOAUDIO ] != "" ) 
            { 
                // store textbox values in record and serialize record 
                try 
                { 
                    // get video and audio code value from textbox 
                    int videoandaudioCode = Int32.Parse( values[ ( int ) TextBoxIndices.VIDEOAUDIO ] ); 
 
                    //determine wheterh videoandaudioCode is valid 
                    if ( videoandaudioCode > 0 ) 
                    { 
                        //store textbox fields in record 
                        class1.Videoandaudio = videoandaudioCode; 
                        class1.Title = values[ ( int ) TextBoxIndices.TITLE ]; 
                        class1.Category = values[ ( int ) TextBoxIndices.CATEGORY ]; 
                        class1.Certification = values[ ( int ) TextBoxIndices.CERTIFICATION ]; 
                        class1.Copies = Int32.Parse( values[ ( int ) TextBoxIndices.COPIES ]); 
                    }//end if 
                    else{ 
                        //notify user if invalid video and audio code 
                        MessageBox.Show( " invalid code ", "error", 
                            MessageBoxButtons.OK, MessageBoxIcon.Error ) ; 
                    }//end else 
                }//endtry 
                //notify user if error occurs in seialization 
                catch ( IOException ) 
                { 
                    MessageBox.Show( "error writing to file" , "error", 
                        MessageBoxButtons.OK, MessageBoxIcon.Error ); 
                }//end catch 
                //notify user if eror occurs regarding parameter format 
                catch ( FormatException )  
                { 
                    MessageBox.Show( "invalid format", "error", 
                        MessageBoxButtons.OK, MessageBoxIcon.Error ); 
                }//end catch 
            }//end if 
 
            ClearTextBoxes(); //clear textbox values 
        }//end method enter button_ click 
 
        //handler for exitButton Click 
        private void exitButton_Click(object sender, EventArgs e) 
        { 
            //dtermine wheteher file exists 
            if (output != null) 
            { 
                try 
                { 
                    fileWriter.Close(); //close streamwriter 
                    output.Close(); //close file 
 
                }// end try 
                //notify user of error closing file 
                catch (IOException) 
                { 
                    MessageBox.Show(" cannot close file", "error", 
                        MessageBoxButtons.OK, MessageBoxIcon.Error); 
                }//end catch 
            }//end if 
 
            Application.Exit(); 
        }//end method 
    }// end class 
}




sorry for posting all the code i am just hoping someone could help me find the error for this...

so frustrated herer

need some help

thx


;D

Last edited by shabbir; 1Apr2009 at 08:58.. Reason: Code blocks
0
shabbir's Avatar, Join Date: Jul 2004
Go4Expert Founder
Your Form1 is derived from Form and so the methods from Form are being derived as private and you need to change that,