.NET 4.x При streamreader.ReadLine() выскакивает ошибка object reference not set to an instance of object - C#
Формулировка задачи:
Здраствуйте, у меня вдруг появилась такая проблема, что при streamreader.ReadLine() выскакивает ошибка object reference not set to an instance of object
вот код процедуры:
по началу ругаеться только не парвую строку считывания, но думаю что и на все остальные так же будет.
не могу понять в чем же проблема, т.к. конструктор класа таков:
а масив даных таков:
ничего не помогает(
мои сэтеры:
а так же описание проблеми:
где 108 рядок это рядок вызова процедуры, а 436 это :
помогите пожалуйста, ато я только недавно начал изучать С#, а полазив по форумах с похожей проблемой все равно не смог с ней справится.
Листинг программы
- public void ReadFile()
- {
- StreamReader streamreader = new StreamReader("Exhibitions.txt");
- FileInfo file = new FileInfo("Exhibitions.txt");
- First();
- _current = 0;
- string hourformat = "t";
- string dateformat = "dd.MM.yyyy";
- while (!streamreader.EndOfStream)
- {
- _exhibitions[_current].set_name_exh(streamreader.ReadLine());
- _exhibitions[_current].set_description_exh(streamreader.ReadLine());
- _exhibitions[_current].set_category_exh(streamreader.ReadLine());
- _exhibitions[_current].set_autor_exh(streamreader.ReadLine());
- _exhibitions[_current].set_start_date_exh(DateTime.ParseExact(streamreader.ReadLine(), dateformat, System.Globalization.CultureInfo.InvariantCulture));
- _exhibitions[_current].set_end_date_exh(DateTime.ParseExact(streamreader.ReadLine(), dateformat, System.Globalization.CultureInfo.InvariantCulture));
- _exhibitions[_current].set_start_hour_exh(DateTime.ParseExact(streamreader.ReadLine(), hourformat, System.Globalization.CultureInfo.InvariantCulture));
- _exhibitions[_current].set_end_hour_exh(DateTime.ParseExact(streamreader.ReadLine(), hourformat, System.Globalization.CultureInfo.InvariantCulture));
- // out_all_result(_exhibitions[_current]);
- _current++;
- }
- streamreader.Close();
- }
Листинг программы
- public Exhibitions()
- {
- name_exh = "";
- description_exh = "";
- category_exh = "";
- autor_exh = "";
- start_date_exh = DateTime.Now;
- end_date_exh = DateTime.Now;
- start_hour_exh = DateTime.Now;
- end_hour_exh = DateTime.Now;
- }
Листинг программы
- public Exhibitions[] _exhibitions = new Exhibitions[50];
- //даже делал так пере запуском процедуры
- private Exhibitions exhibitions;
- public void arraies()
- {
- exhibitions = new Exhibitions();
- for(int i = 0;i<50;i++)
- {
- _exhibitions[i] = exhibitions;
- }
- }
Листинг программы
- public void set_name_exh(string name)
- {
- name_exh = name;
- }
- public void set_description_exh(string description)
- {
- description_exh = description;
- }
- public void set_category_exh(string category)
- {
- category_exh = category;
- }
- public void set_autor_exh(string autor)
- {
- autor_exh = autor;
- }
- public void set_start_date_exh(DateTime start_date)
- {
- start_date_exh = start_date;
- }
- public void set_end_date_exh(DateTime end_date)
- {
- end_date_exh = end_date;
- }
- public void set_start_hour_exh(DateTime start_hour)
- {
- start_hour_exh = start_hour;
- }
- public void set_end_hour_exh(DateTime end_hour)
- {
- end_hour_exh = end_hour;
- }
System.NullReferenceException не обработано
HResult=-2147467261
Message=Object reference not set to an instance of an object.
Source=analysis system exhibiting
StackTrace:
at analysis_system_exhibiting.Exh_iter.ReadFile() in c:\Users\_DarkSiR_\Desktop\курсова\analysis system exhibiting\analysis system exhibiting\Exhibitions.cs:line 436
at analysis_system_exhibiting.Form1.button4_Click(Object sender, EventArgs e) in c:\Users\_DarkSiR_\Desktop\курсова\analysis system exhibiting\analysis system exhibiting\Form1.cs:line 108
at System.Windows.Forms.Control.OnClick(EventArgs e)
at System.Windows.Forms.Button.OnClick(EventArgs e)
at System.Windows.Forms.Button.OnMouseUp(MouseEventArgs mevent)
at System.Windows.Forms.Control.WmMouseUp(Message& m, MouseButtons button, Int32 clicks)
at System.Windows.Forms.Control.WndProc(Message& m)
at System.Windows.Forms.ButtonBase.WndProc(Message& m)
at System.Windows.Forms.Button.WndProc(Message& m)
at System.Windows.Forms.Control.ControlNativeWindow.OnMessage(Message& m)
at System.Windows.Forms.Control.ControlNativeWindow.WndProc(Message& m)
at System.Windows.Forms.NativeWindow.DebuggableCallback(IntPtr hWnd, Int32 msg, IntPtr wparam, IntPtr lparam)
at System.Windows.Forms.UnsafeNativeMethods.DispatchMessageW(MSG& msg)
at System.Windows.Forms.Application.ComponentManager.System.Windows.Forms.UnsafeNativeMethods.IMsoComponentManager.FPushMes sageLoop(IntPtr dwComponentID, Int32 reason, Int32 pvLoopData)
at System.Windows.Forms.Application.ThreadContext.RunMessageLoopInner(Int32 reason, ApplicationContext context)
at System.Windows.Forms.Application.ThreadContext.RunMessageLoop(Int32 reason, ApplicationContext context)
at System.Windows.Forms.Application.Run(Form mainForm)
at analysis_system_exhibiting.Program.Main() in c:\Users\_DarkSiR_\Desktop\курсова\analysis system exhibiting\analysis system exhibiting\Program.cs:line 19
at System.AppDomain._nExecuteAssembly(RuntimeAssembly assembly, String[] args)
at System.AppDomain.ExecuteAssembly(String assemblyFile, Evidence assemblySecurity, String[] args)
at Microsoft.VisualStudio.HostingProcess.HostProc.RunUsersAssembly()
at System.Threading.ThreadHelper.ThreadStart_Context(Object state)
at System.Threading.ExecutionContext.RunInternal(ExecutionContext executionContext, ContextCallback callback, Object state, Boolean preserveSyncCtx)
at System.Threading.ExecutionContext.Run(ExecutionContext executionContext, ContextCallback callback, Object state, Boolean preserveSyncCtx)
at System.Threading.ExecutionContext.Run(ExecutionContext executionContext, ContextCallback callback, Object state)
at System.Threading.ThreadHelper.ThreadStart()
InnerException:
Листинг программы
- _exhibitions[_current].set_name_exh(streamreader.ReadLine());
Листинг программы
- public void WriteFile(string name, string description, string category, string autor, string start_date, string end_date, string start_hour, string end_hour)
- {
- StreamWriter streamwriter;
- FileInfo file = new FileInfo("Exhibitions.txt");
- streamwriter = file.AppendText();
- streamwriter.WriteLine(name);
- streamwriter.WriteLine(description);
- streamwriter.WriteLine(category);
- streamwriter.WriteLine(autor);
- streamwriter.WriteLine(start_date);
- streamwriter.WriteLine(end_date);
- streamwriter.WriteLine(start_hour);
- streamwriter.WriteLine(end_hour);
- streamwriter.Close();
- }
- //которая вызывается вот сдесь:
- private void button1_Click(object sender, EventArgs e)
- {
- iter = new Exh_iter();
- string hourformat = "t";
- string dateformat = "dd.MM.yyyy";
- if ((this.textBox1.Text != "") && (this.textBox2.Text != "") &&(this.textBox3.Text != "") &&(this.textBox4.Text != "") &&(this.textBox5.Text != "") &&(this.textBox6.Text != "") &&(this.textBox7.Text != "") &&(this.richTextBox1.Text != ""))
- {
- string name = this.textBox1.Text;
- string description = this.richTextBox1.Text;
- string category = this.textBox2.Text;
- string autor = this.textBox7.Text;
- string start_date = this.textBox3.Text;
- string end_date = this.textBox4.Text;
- string start_hour = this.textBox5.Text;
- string end_hour = this.textBox6.Text;
- iter.WriteFile(name, description, category, autor, start_date, end_date, start_hour, end_hour);
- this.Hide();
- this.Close();//кстати эта функция тоже почему то не работает, но хоть ошибку не выбивает, просто не закрывает форму. ниодну.
- Form1 form1 = new Form1();
- form1.HideToolStripMenuItem();
- form1.ShowDialog();
- }
- else
- {
- Form6 form6 = new Form6();
- form6.ShowDialog();
- }
- }
Решение задачи: «.NET 4.x При streamreader.ReadLine() выскакивает ошибка object reference not set to an instance of object»
textual
Листинг программы
- for (i = 0; i < 50; i++)
- {
- if (search_result[i] == null) break;
- this.richTextBox1.Text += iter.out_all_result(search_result[i]);
- }
ИИ поможет Вам:
- решить любую задачу по программированию
- объяснить код
- расставить комментарии в коде
- и т.д