-1

I have an exception that says this:

System.NullReferenceException

when adding an item to a combobox with this code:

namespace Veterinari
{
    public partial class Diagnostico : Form
    {
        int tipo;

        public Diagnostico()
        {
            InitializeComponent();
        }

        private void button1_Click(object sender, EventArgs e)
        {
            Principal prin = new Principal(tipo);
            prin.Show();
            this.Hide();
        }

        private void button2_Click(object sender, EventArgs e)
        {
            Principal prin = new Principal(tipo);
            prin.Show();
            this.Hide();
        }
    }
}
marc_s
  • 732,580
  • 175
  • 1,330
  • 1,459

1 Answers1

0

The int tipo is never instantiated.

This means that it will always be null until you set its value:

public Diagnostico()
{
    tipo = 0;
    InitializeComponent();
}
Minijack
  • 726
  • 7
  • 23