[Gtk-sharp-list] Problem with event handlers: GtkSharp.voidObjectSignal
Marc Eilens
marc.eilens@gmx.de
Fri, 7 Mar 2003 18:06:01 +0100
-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1
Hi guys,
just installed GtkSharp and had a look at some examples I got on a CD from a
magazine.
Running the example code attached (I simplified the original code to a
minimum) results in following exception:
>>>
Unhandled Exception: System.NullReferenceException: A null value was found
where an object instance was required
in (unmanaged) 06 GtkSharp.voidObjectSignal:g_signal_connect_data
(intptr,string,GtkSharp.voidObjectDelegate,int,intptr,int)
in <0x00004> 06 GtkSharp.voidObjectSignal:g_signal_connect_data
(intptr,string,GtkSharp.voidObjectDelegate,int,intptr,int)
in <0x000ba> 00 GtkSharp.voidObjectSignal:.ctor
(GLib.Object,intptr,string,System.Delegate,System.Type)
in <0x00095> 00 Gtk.Button:add_Clicked (System.EventHandler)
in <0x000af> 00 .Example:CreateGui ()
in <0x00041> 00 .Sample:Main ()
<<<
I'm totally new to GTK and quite new to C# but for the C# side, I think I
don't do anything forbidden. And for the GTK side, if I leave out the code
adding the event handler to the button, everything is ok.
In the docs, I found a similar example (Hello 2nd try from the go-mono
tutorial) which works. The difference to my code fragment is that the GUI is
set up in the Main method and not in a method of another class.
What am I doing wrong?
FYI: I'm using mono 0.22, gtk-sharp-0.8 and gtk+-2.2.1 on a SuSE Linux 8.1
system.
Thanks in advance,
Marc
>>>
using Gtk;
using GtkSharp;
using System;
class Example
{
Window win;
Statusbar statusbar;
public void CreateGui()
{
win = new Window ("Example");
Button button = new Button("OK");
button.Clicked += new EventHandler(ButtonClicked);
win.Add(button);
win.ShowAll ();
}
static void ButtonClicked(object sender, EventArgs e)
{
Console.WriteLine("button clicked");
}
}
class Sample {
public static void Main()
{
Application.Init ();
Example example = new Example();
example.CreateGui();
Application.Run();
}
}
<<<
-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.0.7 (GNU/Linux)
iD8DBQE+aNF/PyFrQq7n9YkRAurfAJ9sYoIqxZl/HPvwScg3YRHLpJlqzgCfY3LD
S57LUwo/rLqaajNlx3lcUQU=
=HiEX
-----END PGP SIGNATURE-----