簡體   English   中英

在將對象添加到列表中時,對象引用未設置為對象的實例

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

在以下代碼中,對於我來說還是一個未知的原因,它一直在標題中引發異常。

            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"); }

我只是想在圖形列表中添加圖形對象

        private List<Drawing> drawings;

供以后使用,但我不知道為什么拋出此異常。

確保圖紙已初始化:

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