使用Gtk库TreeViewColumn时,使用Mono C#获取NullReferenceException

时间:2014-09-10 04:43:42

标签: c# mono treeview

我正在尝试在Gtk#TreeView中显示sqlite数据库,但是当我将列附加到树视图中时,会发生NullReferenceException。

这是我的代码:

using System;
using Gtk;
using libraryGueyWrapper;

public partial class MainWindow: Gtk.Window
{   

    public MainWindow (): base (Gtk.WindowType.Toplevel)
    {
        Tree ();
        Build ();
    }

    public void Tree ()
    {
        //Create the name column
        Gtk.TreeViewColumn name = new Gtk.TreeViewColumn ();
        name.Title = "Name";

        table.AppendColumn (name); //Exception occurs on this line
    }

    protected void OnDeleteEvent (object sender, DeleteEventArgs a)
    {
        Application.Quit ();
        a.RetVal = true;
    }
}

这是我得到的错误:

System.NullReferenceException: Object reference not set to an instance of an object
  at MainWindow.Tree () [0x00019] in /home/ayush/databaseManagementSystem/libraryGueyWrapper/libraryGueyWrapper/MainWindow.cs:20
  at MainWindow..ctor () [0x00009] in /home/ayush/databaseManagementSystem/libraryGueyWrapper/libraryGueyWrapper/MainWindow.cs:10
  at libraryGueyWrapper.TreeView.Main () [0x00006] in /home/ayush/databaseManagementSystem/libraryGueyWrapper/libraryGueyWrapper/Program.cs:11

我是Mono和c#的新手,这可能是一个简单的错误,但我无法弄清楚它是什么。

注意:我读过this link并没有真正帮助。另外,我用Google搜索并找到了捕获NullReferenceException的链接,但我想要做的就是修复它。

0 个答案:

没有答案