Не работает код - NullReferenceException - C#
Формулировка задачи:
Вот сам код:
Класс Report
Метод где происходит ошибка:
Переменная reports обьявляется в начале класса так: Report[] reports;
Прошу дать исправный код.
class Report { public const string server = ""; //Он есть,я не написал,чтобы GET запросы не делали public string auther; public string message; public string requist; public void Requist(string text) { Form1.wc.DownloadString(server + "add.php?nick=" + auther + "&FromAdmin=" + text); this.requist = text; } }
void LoadReports(object sender,EventArgs e) { ReportPage = 1; string reports = GetUTF8(wc.DownloadString(Report.server + "fb.php")); if (reports == "no_reporter") { MessageBox.Show("Репортов нету"); return; } string[] temp = reports.Split('|'); for (int i = 1; i < temp.Length; i++) { this.reports[i].auther = temp[i].Split('-')[0]; //тут ошибки this.reports[i].message = temp[i].Split('-')[1]; //тут this.reports[i].requist = temp[i].Split('-')[2]; //тут } SortReportsForPage(null,null); }
Решение задачи: «Не работает код - NullReferenceException»
textual
Листинг программы
this.reports = new Report[???]; for (int i = 1; i < temp.Length; i++) { this.reports[i] = new Report(); var tokens = temp[i].Split('-'); this.reports[i].auther = tokens[0]; this.reports[i].message = tokens[1]; this.reports[i].requist = tokens[2]; }
ИИ поможет Вам:
- решить любую задачу по программированию
- объяснить код
- расставить комментарии в коде
- и т.д