0

I am trying to populate my checkedListBox with a txt file.

Here is my code:

public Form1()
{
   StreamReader sr1 = new StreamReader(allatPath, Encoding.Default);
   while(!sr1.EndOfStream)
   {
       allat = new Allat(sr1.ReadLine(), sr1.ReadLine(), Convert.ToInt32(sr1.ReadLine()), sr1.ReadLine());
       allatok.Add(allat);
       checkedListBox1.Items.Add(allat.Nev);
   }

   InitializeComponent();
}

I get the following error:

System.NullReferenceException: 'Object reference not set to an instance of an object.'

checkedListBox1 was null.

user3599604
  • 31
  • 10
  • How/where did you declare and initialize `checkedListBox1`? – Camilo Terevinto Jun 14 '18 at 21:46
  • 4
    It seems pretty clear. You are using a control before [calling InitializeComponent](https://stackoverflow.com/questions/12297079/very-simple-definition-of-initializecomponent-method) – Steve Jun 14 '18 at 21:47

0 Answers0