public void OnCombobox1Changed (object sender, EventArgs e)
{
handler.name = combobox1.ActiveText;
}
The code sample is a handler (auto generated by gtk# using Mono's gui developer) with my own variable assignment in it. I have three classes, a win class that contains my gui components, which the sample is from, a database handler class, and my main class. Handler is already instantiated in main and works with no problems, I can successfully populate combobox1
from my database using handler. I can put a simple Console.Writeline(combobox1.ActiveText);
in the signal handler above instead of what's there and it works perfectly. I cannot figure out why this variable assignment doesn't work, handler.name
is a class level string variable and combobox1.ActiveText
is a string as well, so variable type isn't the problem. When I run this with the above code instead of the Console.Writeline(combobox1.ActiveText);
I get the following error as soon as I select a string from my combobox1
:
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.NullReferenceException: Object reference not set to an instance of an object at MainWindow.OnCombobox1Changed (System.Object sender, System.EventArgs e) [0x00000] in /home/slothofdoom/Desktop/Programming/Tracker/Tracker/MainWindow.cs:63 at (wrapper managed-to-native) System.Reflection.MonoMethod:InternalInvoke (System.Reflection.MonoMethod,object,object[],System.Exception&) at System.Reflection.MonoMethod.Invoke (System.Object obj, System.Reflection.BindingFlags invokeAttr, System.Reflection.Binder binder, System.Object[] parameters, System.Globalization.CultureInfo culture) [0x00032] in /build/mono-5.2.0.224/mcs/class/corlib/System.Reflection/MonoMethod.cs:305 --- End of inner exception stack trace --- at System.Reflection.MonoMethod.Invoke (System.Object obj, System.Reflection.BindingFlags invokeAttr, System.Reflection.Binder binder, System.Object[] parameters, System.Globalization.CultureInfo culture) [0x00043] in /build/mono-5.2.0.224/mcs/class/corlib/System.Reflection/MonoMethod.cs:313 at System.Reflection.MethodBase.Invoke (System.Object obj, System.Object[] parameters) [0x00000] in /build/mono-5.2.0.224/mcs/class/referencesource/mscorlib/system/reflection/methodbase.cs:229 at System.Delegate.DynamicInvokeImpl (System.Object[] args) [0x000e1] in /build/mono-5.2.0.224/mcs/class/corlib/System/Delegate.cs:461 at System.MulticastDelegate.DynamicInvokeImpl (System.Object[] args) [0x00008] in /build/mono-5.2.0.224/mcs/class/corlib/System/MulticastDelegate.cs:67 at System.Delegate.DynamicInvoke (System.Object[] args) [0x00000] in /build/mono-5.2.0.224/mcs/class/corlib/System/Delegate.cs:406 at GLib.Signal.ClosureInvokedCB (System.Object o, GLib.ClosureInvokedArgs args) [0x0007d] in <940f51fcd0434c359bfa4fdc8e64ad03>:0 at GLib.Signal+SignalClosure.Invoke (GLib.ClosureInvokedArgs args) [0x0000c] in <940f51fcd0434c359bfa4fdc8e64ad03>:0 at GLib.Signal+SignalClosure.MarshalCallback (System.IntPtr raw_closure, GLib.Value* return_val, System.UInt32 n_param_vals, GLib.Value* param_values, System.IntPtr invocation_hint, System.IntPtr marshal_data) [0x00050] in <940f51fcd0434c359bfa4fdc8e64ad03>:0 at GLib.ExceptionManager.RaiseUnhandledException (System.Exception e, System.Boolean is_terminal) [0x00000] in <940f51fcd0434c359bfa4fdc8e64ad03>:0 at GLib.Signal+SignalClosure.MarshalCallback (System.IntPtr raw_closure, GLib.Value* return_val, System.UInt32 n_param_vals, GLib.Value* param_values, System.IntPtr invocation_hint, System.IntPtr marshal_data) [0x00000] in <940f51fcd0434c359bfa4fdc8e64ad03>:0 at Gtk.Application.gtk_main () [0x00000] in :0 at Gtk.Application.Run () [0x00000] in :0 at Tracker.MainClass.Main (System.String[] args) [0x0002e] in /home/slothofdoom/Desktop/Programming/Tracker/Tracker/Program.cs:54
Any help with understanding how to fix this would be very appreciated.
Edit: I have cleared many NullReferenceExceptions before, normally it turns out to be due to an error in scope, but this time I am asking for help because I do not understand how I could be out of scope, it's also worth mentioning I normally get the NullReferenceException when I try to compile, and it doesn't have all those glib warnings and stuff.
Edit2: It may also be relevant to say that in the process of attempting to debug this I tried making the name variable in the same class as my signal handler, and it worked fine. I have also tried to make setters in the win class where my signal handler is located to set handler.name in my database handler class and it throws the exact same error, it's like I only get the error when I try to assign the string in combobox1.ActiveText to a variable in another class, or if I assign it to a variable in win class I also get the error if I try to pass that variable to another class for manipulation of any kind