简体   繁体   中英

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>();

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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