object reference not set to an instance of an object in c#
<blockquote>
  <p><strong>Possible Duplicate:</strong><br>
  <a href="http://stackoverflow.com/questions/55130/nullreferenceexception-on-instanciated-object">NullReferenceException on instanciated object?</a><br>
  <a href="http://stackoverflow.com/questions/4660142/what-is-a-nullreferenceexception-in-net">What is a NullReferenceException in .NET?</a>  </p>
</blockquote>



<p>Error:   </p>

<blockquote>
  <p>Object reference not set to an instance of an object</p>
</blockquote>

<p>Hi every one I am getting above error when I scanned multiple records (ex:2 records) and working for scanning of one record .</p>

<pre><code>   #region declare
    private string RtoOffice = string.Empty;
    string paths = string.Empty;
    ADFScan _scanner;
    int[] _colors = { 1, 2, 4 };
    int count = 0;
    static int num = 0;
    static int  NoTimes=0;
    int n;
    Bitmap[] item;
    string filename = string.Empty;
    #endregion
</code></pre>

<p>// scanning of documents</p>

<pre><code>private void BtnScan_Click(object sender, EventArgs e)
    {

        try
        {
             n = popuprds.nofrecords;-------&gt; enter by end user to scan how many documents
            item = new Bitmap[n];
            NoTimes = Convert.ToInt32(popuprds.nofrecords);
            string path = string.Empty;

            string[] appPath = Convert.ToString(Application.ExecutablePath).Split('\\');
            for (int i = 0; i &lt; appPath.Length - 4; i++)
            {
                path += appPath[i] + "\\";
            }
             paths = path + "PROJECT SCANNED\\" + txtDLNo.Text + ".pdf";

            _scanner = new ADFScan();
            _scanner.Scanning += new EventHandler&lt;WiaImageEventArgs&gt;(_scanner_Scanning);
            _scanner.ScanComplete += new EventHandler(_scanner_ScanComplete);
            ScanColor selectedColor = (ScanColor)_colors[2];
            _scanner.BeginScan(selectedColor, 150);
        }
        catch(Exception ex)------------&gt; getting exception here
        {
            if(ex.Message == "Exception from HRESULT: 0x80210015")
            MessageBox.Show("No Devices Found..!","Message",MessageBoxButtons.OK,MessageBoxIcon.Information);
            else
                MessageBox.Show(ex.Message, "Message", MessageBoxButtons.OK, MessageBoxIcon.Information);
        }
    }
    void _scanner_ScanComplete(object sender, EventArgs e)
    {
        DialogResult dlgresult = MessageBox.Show("Do You Want to Scan More Records ?", "Scan Conformation", MessageBoxButtons.YesNo, MessageBoxIcon.Question, MessageBoxDefaultButton.Button1);
        if (dlgresult == DialogResult.Yes)
        {
            BtnScan_Click(sender, e);
        }
        else
        {

            Bmec.ScanLibrary.Converters.PdfConverter pdf = new PdfConverter();
            pdf.SaveFrom(item, paths);
            MessageBox.Show("PDF created Successfully");

          //  MessageBox.Show("Scan Complete");
        }
    }
    void _scanner_Scanning(object sender, WiaImageEventArgs e)
    {


        if (num &lt; n)
        {
            item[num] = new Bitmap(e.ScannedImage);
            num++;
        }
</code></pre>
