简体   繁体   English

在将对象添加到列表中时,对象引用未设置为对象的实例

[英]Object reference not set to an instance of an object on adding an object to a list

In the following code for, yet an unknown to me reason it keeps on throwing a the exception in the title. 在以下代码中,对于我来说还是一个未知的原因,它一直在标题中引发异常。

            try
        {
            conn.Open();
            createDraw.ExecuteNonQuery();
            rdr = getDrawId.ExecuteReader();
            string rd = rdr[0].ToString();
            int tid = Int32.Parse(rd);

            Drawing dr = new Drawing(tid, pos, orientation, defaultColour, 200.0, 300.0, fname, "local");
            this.NoteScatterView.Items.Add(dr.getSvi());
            if (dr != null) { drawings.Add(dr); }

        }
        catch (Exception ex) { Microsoft.Surface.UserNotifications.RequestNotification("Unable to create Drawing", ex.Message + "in Session.createDrawing"); }

I'm just trying to add the drawing object in a list of Drawings 我只是想在图形列表中添加图形对象

        private List<Drawing> drawings;

for later use, but I don't know why this exception is thrown. 供以后使用,但我不知道为什么抛出此异常。

确保图纸已初始化:

private List<Drawing> drawings = new List<Drawing>();

您需要创建一个List实例

private List<Drawing> drawings = new List<Drawing>();

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM