null - NullReferenceException was unhandles using Windows Forms c# -
i getting exception
nullreferenceexception unhandled
i have tried , tried again solve hours later , i'm coming here help.
this i'm getting error:
form1 objectform1 = new form1(); (int = 0; < 1; i++) { objectform1.taskbox.items.add( objectform1.taskitems[i].taskname + objectform1.taskitems[i].taskdescription + objectform1.taskitems[i].taskpriority + objectform1.taskitems[i].taskduedate + objectform1.taskitems[i].taskcompletion); }
i know it's not lot work above, here other section of code, trying create object references instead of using lists etc, these items meant show in listbox
:
using system; using system.collections.generic; using system.componentmodel; using system.data; using system.drawing; using system.linq; using system.text; using system.threading.tasks; using system.windows.forms; namespace programming_and_data_structures_todolist { public partial class form1 : form { public objectfile[] taskitems = new objectfile[10]; public form1() { initializecomponent(); } public void formmain() { //creating form links----| form2 objectform2 = new form2(); form1 objectform1 = new form1(); //---------------------------| //above creating object reference //below setting values string taskname = objectform2.tasknamebox.text; string taskdescription = objectform2.taskdescbox.text; decimal taskpriority = objectform2.priorityupdown.value; string taskduedate = objectform2.datetimepicker.value.toshortdatestring(); string taskcompletion = objectform2.completion; (int = 0; < 1; i++) { taskitems[i] = new objectfile(convert.tostring(taskname), convert.tostring(taskdescription), convert.toint32(taskpriority), convert.tostring(taskduedate), taskcompletion); } } private void newtoolstripmenuitem_click(object sender, eventargs e) { form2 form2object = new form2(); //creates object link form2 form2object.showdialog(); //shows form2 (task input menu) } private void edittoolstripmenuitem_click(object sender, eventargs e) { environment.exit(0); //exits whole application } public void optionstoolstripmenuitem_click(object sender, eventargs e) { } } //object class public class objectfile { public string taskname { get; set; } public string taskdescription { get; set; } public decimal taskpriority { get; set; } public string taskduedate { get; set; } public string taskcompletion { get; set; } public objectfile(string taskname, string taskdescription, decimal taskpriority, string taskduedate, string taskcompletion) { taskname = taskname; taskdescription = taskdescription; taskpriority = taskpriority; taskduedate = taskduedate; taskcompletion = taskcompletion; } } }
you setup taskitems
in formmain
, there no call method in code fails.
possible fix - call method
form1 objectform1 = new form1(); objectform1.formmain(); (int = 0; < 1; i++) ....
for standard steps investigate nre check out what nullreferenceexception, , how fix it?
Comments
Post a Comment