[Mono-list] Reference problem or misunderstanding

Rob Brown-Bayliss uncertain.genius at gmail.com
Sat Sep 9 17:41:05 EDT 2006

Hi, I am getting a null reference error when trying to set a value in Gconf.

But I am sure the problem is my misunderstanding of the way c# handles
classes etc.

I have a Prefs class which deals with GConf.

in my main app class I have the following:
	public Prefs prefs;
	public MainWindow (): base ("")
		Stetic.Gui.Build (this, typeof(MainWindow));
		Prefs prefs = new Prefs();
		prefs.setkey (Prefs.BODY_KEY, "test");   //  <-- This Works!!!

further down the class I have this method:
	protected virtual void OnBodyChanged(object sender, System.EventArgs e)
		Console.WriteLine("Body Changed..");
		ComboBox combo = sender as ComboBox;
        	if (sender == null)
          	TreeIter iter;
          	if (combo.GetActiveIter (out iter))
          		body = (string) combo.Model.GetValue (iter, 0);
          		Console.WriteLine (body);
          		try {
          			prefs.setkey (Prefs.BODY_KEY, body);  //  <-- This Fails!!!
       			} catch (System.NullReferenceException err) {
						Console.WriteLine("Null Reference error in MainWindow.cs");

The bit above that fails, I have tried  this.prefs.setkey
(Prefs.BODY_KEY, body); but that also fails.

Can any one point out what is wrong?  I have been pooring ove c# web
sites but th=ey all seem to deal with single class examples.



More information about the Mono-list mailing list