Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/vb.net/14.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Vb.net &引用;对象引用未设置为对象的实例;在添加到列表时_Vb.net_Exception_Nullreferenceexception_Object Reference - Fatal编程技术网

Vb.net &引用;对象引用未设置为对象的实例;在添加到列表时

Vb.net &引用;对象引用未设置为对象的实例;在添加到列表时,vb.net,exception,nullreferenceexception,object-reference,Vb.net,Exception,Nullreferenceexception,Object Reference,我的程序需要一些帮助。当我使用自定义命令运行VB.NET程序时,会出现此错误 **************例外文本************** System.NullReferenceException:对象引用未设置为对象的实例。 在C:\Users\Daniel\My Programs\Visual Basic\SeaCow\SeaCow\SeaCow\SeaCow\Main.vb中的SeaCow.Main.DayView1\u ResolveAppoints(对象发送者,ResolveAp

我的程序需要一些帮助。当我使用自定义命令运行VB.NET程序时,会出现此错误

**************例外文本************** System.NullReferenceException:对象引用未设置为对象的实例。 在C:\Users\Daniel\My Programs\Visual Basic\SeaCow\SeaCow\SeaCow\SeaCow\Main.vb中的SeaCow.Main.DayView1\u ResolveAppoints(对象发送者,ResolveAppointmentsEventArgs参数):第120行 在Calendar.DayView.onResolveAppointment(ResolveAppointmentsEventArgs参数)处 在Calendar.DayView.OnPaint(PaintEventArgs e) 在System.Windows.Forms.Control.PaintEventArgs处理(PaintEventArgs e,Int16层) 在System.Windows.Forms.Control.WmPaint(Message&m)中 位于System.Windows.Forms.Control.WndProc(Message&m) 在System.Windows.Forms.NativeWindow.Callback(IntPtr hWnd、Int32 msg、IntPtr wparam、IntPtr lparam)中

根据错误代码,下面的“for each”循环导致NullReferenceException错误。默认情况下,“约会”列表未指定任何内容,我无法找到在何处调用ResolveAppoints函数

    Private Sub DayView1_ResolveAppointments(ByVal sender As Object, ByVal args As Calendar.ResolveAppointmentsEventArgs) Handles DayView1.ResolveAppointments
    Dim m_Apps As New List(Of Calendar.Appointment)

    For Each m_App As Calendar.Appointment In appointments
        If (m_App.StartDate >= args.StartDate) AndAlso (m_App.StartDate <= args.EndDate) Then
            m_Apps.Add(m_App)
        End If
    Next

    args.Appointments = m_Apps
End Sub

有人有什么建议吗?

您的
Calendar.DayView
控件似乎在其对
OnPaint
的覆盖范围内调用了
OnResolveAppoints
函数。我建议您检查那里的代码


同时,如果
约会
DayView1\u ResolveAppoints
显然是
DayView1
控件的
ResolveAppoints
事件的事件处理程序,那么您可以跳过每个
。如果每个
都抛出异常,那么这意味着
约会
在当时是
,而不是您期望的空列表。加

If appointments Is Nothing Then
    Return
End If

在每个
循环的
之前。

名称以
m
开头的变量是什么?对我来说,这是一种通常用于指示成员字段(而不是局部变量)的约定;我觉得这太奇怪了!几乎所有
NullReferenceException
的情况都是相同的。有关提示,请参阅“”。
protected override void OnPaint(PaintEventArgs e)
    {
        e.Graphics.SmoothingMode = System.Drawing.Drawing2D.SmoothingMode.AntiAlias;

        // resolve appointments on visible date range.
        ResolveAppointmentsEventArgs args = new ResolveAppointmentsEventArgs(this.StartDate, this.StartDate.AddDays(daysToShow));
        ResolveAppointments(args);

        using (SolidBrush backBrush = new SolidBrush(renderer.BackColor))
            e.Graphics.FillRectangle(backBrush, this.ClientRectangle);

        // Visible Rectangle
        Rectangle rectangle = new Rectangle(0, 0, this.Width - VScrollBarWith, this.Height);

        DrawDays(ref e, rectangle);

        DrawHourLabels(ref e, rectangle);

        DrawDayHeaders(ref e, rectangle);
    }
If appointments Is Nothing Then
    Return
End If