Null reference in C# Mono / GTK#
I am trying to create a simple note-taking application for my own use. The
idea is to learn C#/Mono XML editing.
I can't find a NullReference that the compiler is complaining about. No
idea why. I can't see it. After few days of searching I give up... help.
:)
Here is the code that is making a bug. The application runs fine until I
press a button to Add new note. It just crashes. The add_activated
function runs when a button is pressed and it should use AddNote function.
The code is incomplete and it certainly has some logic bugs. But I can
handle those. I'm just wondering why it 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 {
get
{
return this.title;
}
set
{
this.title = value;
}
}
public string Text
{
get
{
return this.text;
}
set
{
this.text = value;
}
}
public Note (string title, string text)
{
this.Title = title;
this.Text = text;
}
}
}
Runtime:
Marshaling activate signal
Exception in Gtk# callback delegate
Note: Applications can use GLib.ExceptionManager.UnhandledException to
handle the exception.
System.Reflection.TargetInvocationException: Exception has been thrown by
the target of an invocation. ---> System.NotImplementedException: The
requested feature is not implemented.
at Keeper.MainWindow.remove_activated (System.Object sender,
System.EventArgs e) [0x00000] in
/home/tomasz/Programowanie/GTK#/Keeper/Keeper/MainWindow.cs:58
at (wrapper managed-to-native) System.Reflection.MonoMethod:InternalInvoke
(System.Reflection.MonoMethod,object,object[],System.Exception&)
at System.Reflection.MonoMethod.Invoke (System.Object obj, BindingFlags
invokeAttr, System.Reflection.Binder binder, System.Object[] parameters,
System.Globalization.CultureInfo culture) [0x00000] in <filename
unknown>:0
--- End of inner exception stack trace ---
at System.Reflection.MonoMethod.Invoke (System.Object obj, BindingFlags
invokeAttr, System.Reflection.Binder binder, System.Object[] parameters,
System.Globalization.CultureInfo culture) [0x00000] in <filename
unknown>:0
at System.Reflection.MethodBase.Invoke (System.Object obj, System.Object[]
parameters) [0x00000] in <filename unknown>:0
at System.Delegate.DynamicInvokeImpl (System.Object[] args) [0x00000] in
<filename unknown>:0
at System.MulticastDelegate.DynamicInvokeImpl (System.Object[] args)
[0x00000] in <filename unknown>:0
at System.Delegate.DynamicInvoke (System.Object[] args) [0x00000] in
<filename unknown>:0
at GLib.Signal.ClosureInvokedCB (System.Object o, GLib.ClosureInvokedArgs
args) [0x00000] in <filename unknown>:0
at GLib.SignalClosure.Invoke (GLib.ClosureInvokedArgs args) [0x00000] in
<filename unknown>:0
at GLib.SignalClosure.MarshalCallback (IntPtr raw_closure, IntPtr
return_val, UInt32 n_param_vals, IntPtr param_values, IntPtr
invocation_hint, IntPtr marshal_data) [0x00000] in <filename unknown>:0
at GLib.ExceptionManager.RaiseUnhandledException(System.Exception e,
Boolean is_terminal)
at GLib.SignalClosure.MarshalCallback(IntPtr raw_closure, IntPtr
return_val, UInt32 n_param_vals, IntPtr param_values, IntPtr
invocation_hint, IntPtr marshal_data)
at Gtk.Application.gtk_main()
at Gtk.Application.Run()
at Keeper.MainClass.Main(System.String[] args) in
/home/tomasz/Programowanie/GTK#/Keeper/Keeper/Main.cs:line 13
The application was terminated by a signal: SIGHUP
No comments:
Post a Comment