I am trying to make a little program in C# just for practice, but I've encountered a problem that I can't find a solution to anywhere.
Program has 2 textboxes(Ime1 and Dug1) and a button, so when I press the button it creates an object(duznik1) like this:
Duznik duznik1 = new Duznik(Ime1.Text, int.Parse(Dug1.Text));
This is the Duznik class:
public class Duznik
{
public int count = 0;
public string ime;
public int dug;
TextBox[] Imena;
TextBox[] Dugovi;
TextBox[] Vraceno;
TextBox[] Dodato;
public Duznik(string imeDuznika, int kolikoDuguje)
{
ime = imeDuznika;
dug = kolikoDuguje;
Imena[count] = new TextBox();
Imena[count].Text = imeDuznika;
Dugovi[count] = new TextBox();
Dugovi[count].Text = dug.ToString();
Vraceno[count] = new TextBox();
Dodato[count] = new TextBox();
count++;
}
}
So basically, what I want it to do is create TextBox arrays(Imena,Dugovi,Vraceno,Dodato), and populate these arrays with textboxes(which I try to make in the constructor method), but whatever I do, i always get an error at the line "Imena[count].Text = imeDuznika;", and the error says:
An unhandled exception of type 'System.NullReferenceException' occurred in Dugovi.exe
Additional information: Object reference not set to an instance of an object.
I tried to comment out that line, but whatever I do, the same error appears in the constructor method, just on a different line. I am new to programming so any help is welcome, thanks in advance :)