如何解决此“ System.NullReferenceException已引发-对象引用未设置为对象实例”的问题?

时间:2018-07-04 16:03:14

标签: xcode visual-studio

我在行 clickedLabel.StringValue =“尚未单击按钮。” 处出现错误。表示已引发System.NullReferenceException-对象引用未设置为对象的实例。请帮我。

使用系统;

使用AppKit; 使用Foundation;

命名空间Hello_Mac {

public partial class ViewController : NSViewController
{

    private int numberOfTimesClicked = 0;
    public ViewController(IntPtr handle) : base(handle)
    {
    }
    public override void ViewDidLoad()
    {

        base.AwakeFromNib();
        // Set the initial value for the label
        base.ViewDidLoad();
        // Do any additional setup after loading the view.
        clickedLabel.StringValue = "Button has not been clicked yet.";
    }

    public override NSObject RepresentedObject
    {
        get
        {
            return base.RepresentedObject;
        }
        set
        {
            base.RepresentedObject = value;
            // Update the view, if already loaded.
        }
    }
    partial void clickedButton(Foundation.NSObject sender)
    {

        // Update counter and label
        clickedLabel.StringValue = string.Format("The button has been clicked {0} time{1}.", ++numberOfTimesClicked, (numberOfTimesClicked < 2) ? "" : "s");
    }
}

}

0 个答案:

没有答案