Null reference in C# Mono / GTK# -


i trying create simple note-taking application own use. idea learn c#/mono xml editing.

i can't find nullreference compiler complaining about. no idea why. can't see it. after few days of searching give up... help. :)

here code making bug. application runs fine until press button add new note. crashes. add_activated function runs when button pressed , should use addnote function.

the code incomplete , has logic bugs. can handle those. i'm wondering why won't run.

mainactivity.cs:

// (...) protected void add_activated (object sender, system.eventargs e)     {         gtk.textbuffer buffer;                   buffer = textview1.buffer;          note note = new note(entry3.text, buffer.text);               addnote (note);     }       public static void addnote (note note)     {         string xmlfile = "/home/tomasz/.keeper/keeper.xml";          xmldocument xmldoc = new xmldocument ();         xmldoc.load (xmlfile);         xmlnode xmlroot = xmldoc.createelement("keeper");          if (!xmldoc.documentelement.name.equals("keeper") )         {                    xmldoc.appendchild (xmlroot);         }          xmlnode xmlnote = xmldoc.createelement ("note");         xmlnode xmltitle = xmldoc.createelement ("title");         xmlnode xmltext = xmldoc.createelement ("text");          xmlroot.insertafter (xmlroot.lastchild, xmlnote);         xmltitle.innertext = note.title;         xmlnote.insertafter (xmlnote.lastchild, xmltitle);         xmltext.innertext = note.text;         xmlnote.insertafter (xmlnote.lastchild, xmltext);          xmldoc.save (xmlfile);     }       protected void remove_activated (object sender, system.eventargs e)     {         throw new system.notimplementedexception ();     }     } } 

note.cs:

using system;  namespace keeper { public class note {        private string title;     private string text;      public string title {                  {             return this.title;         }         set          {             this.title = value;         }     }     public string text     {                  {             return this.text;         }         set          {             this.text = value;         }     }      public note (string title, string text)     {         this.title = title;         this.text = text;     } } } 

the immediate problem got arguments inserafter mixed up. first 1 should node insert , second 1 should reference node. root element has no children yet, lastchild going null , hence exeption. using null reference point valid, not node add.

there other issues said able fix those, there go.


Comments

Popular posts from this blog

design - Custom Styling Qt Quick Controls -

Unable to remove the www from url on https using .htaccess -