Object reference not set to an instance of an object... Error while using forech
<blockquote>
  <p><strong>Possible Duplicate:</strong><br>
  <a href="http://stackoverflow.com/questions/4660142/what-is-a-nullreferenceexception-in-net">What is a NullReferenceException in .NET?</a>  </p>
</blockquote>



<p>I am developing a simple program. Accepting an arraylist from Form1 and displaying its contents on form2 and I am getting this error.. Plz enlighten me.. Coding goes like this ..</p>

<p>FORM1.cs..............</p>

<pre><code>public partial class Form1 : Form
{
    ArrayList alcar;
    public Form1()
    {
        InitializeComponent();
    }

    private void button1_Click(object sender, EventArgs e)
    {
        string name = textBox1.Text; ; int quantity = int.Parse(textBox2.Text);
        car c = new car(name, quantity);
        if (alcar != null)
        {
            alcar.Add(c);
        }
        else
        {
            alcar = new ArrayList();
            alcar.Add(c);
        }
        Form2 f2 = new Form2();
        f2.Show();
    }
    public ArrayList getArray()
    {
     return alcar;
    }    
}
class car
{
    string name; int quantity;
    public string NAME
    {
        get { return name; }
        set { name = value; }
    }
    public int QUANTITY
    {
        get { return quantity; }
        set { quantity = value; }
    }
    public car(string n, int q)
    {
        name = n; quantity = q;
    }
}
</code></pre>

<p>FORM2.cs.........................</p>

<pre><code>public partial class Form2 : Form
{
    ArrayList al;
    public Form2()
    {
        Form1 f1 = new Form1();
        if (al != null)
        {
            al = f1.getArray();
        }
        else
        {
            al = new ArrayList();
            al = f1.getArray();
        }

        InitializeComponent();
        foreach (car c in al)        // this lne is causing error
        {
            label1.Text = c.NAME;
            label2.Text = Convert.ToString(c.QUANTITY);
        }
    }

}
</code></pre>
