Открытый массив строк вызывает ошибку без четкой причины (System.NullReferenceException)
Я, кажется, получил эту ошибку без причины, я попытался инициализировать массив, но не помог. Я погуглил проблему, но ничего особенного не нашел. Это работало раньше, но я не могу изменить это!
ОШИБКА:
System.NullReferenceException: 'Ссылка на объект не установлена для экземпляра объекта.
КОД:
public partial class Form1 : Form
{
string[] dir;
int x = 2;
public Form1()
{
InitializeComponent();
}
private void folderBrowserDialog1_HelpRequest(object sender, EventArgs e)
{ }
private void button1_Click(object sender, EventArgs e)
{
{
System.Windows.Forms.MessageBox.Show("ERROR......", "NOT IMPLEMENTED YET");
}
}
private void Stp_Click(object sender, EventArgs e)
{
string loc = textBox1.Text;
var dec = MessageBox.Show("ARE YOU SURE YOU WANT TO SET IT UP AT " + loc, "ARE YOU SURE ABOUT THAT?", MessageBoxButtons.YesNo);
if (dec == DialogResult.Yes)
{
System.IO.Directory.CreateDirectory(loc);
if (!System.IO.Directory.Exists(loc))
{
MessageBox.Show("If you see this...uhhh contact me.", "How did you manage to get here?");
}
else
{
//sets up, creates main dir and ID count
MessageBox.Show("Well,the computer here says its done. But check it.", "Succesful");
string fileName = "settings";
string fn = "Id";
string loc2;
string dloc3;
string asdas = "0";
loc2 = System.IO.Path.Combine(loc, fileName);
System.IO.File.WriteAllText(@loc2, loc);
dloc3 = System.IO.Path.Combine(loc, fn);
System.IO.File.WriteAllText(@dloc3, asdas);
dir[2] = dloc3;
dir[0] = loc;
dir[1] = loc2;
}
}
}