NullReferenceException when trying to set class property

后端 未结 7 1696
醉酒成梦
醉酒成梦 2021-01-22 00:56

Basically I have 2 classes, \"Manifest\" and \"BrowserAction\", set out like this:

public class BrowserAction
{
    public string default_icon {get; set;}
    pu         


        
7条回答
  •  北荒
    北荒 (楼主)
    2021-01-22 01:40

    I think the Manifest.browser_action property returns null because you don't initialize it. Create an object before accessing its properties:

    Manifest newManifest = new Manifest();
    newManifest.browser_action = new BrowserAction();
    newManifest.browser_action.default_popup = "popup.html";
    

提交回复
热议问题