空引用异常 - 即使存在新关键字



以下是代码:

            Dim x As New Google.Apis.Calendar.v3.Data.EventAttendee
            x.Email = "xxccxxxxx@gmail.com"
            x.DisplayName = "xxxxx"
            x.ResponseStatus = "Aproveed"
            Dim y As New Google.Apis.Calendar.v3.Data.EventAttendee
            y.Email = "xxxxxxx@gmail.com"
            y.DisplayName = "suji"
            y.ResponseStatus = "Aproveed"
            Dim attndList As New List(Of EventAttendee)
            attndList.Add(x)
            attndList.Add(y)
            Dim googleCalendarEvent As New [Event]()
            googleCalendarEvent.Attendees.Add(y)'<--- throws exception here
            googleCalendarEvent.Attendees.Add(x)

异常详细信息: Object reference not set to an instance of an object . 为什么会这样? 我怎样才能克服这个问题?

更新当我使用时:

 Dim googleCalendarEvent As New [Event]()
  googleCalendarEvent.Attendees = New EventAttendee()

它将错误显示为

无法强制转换类型的对象 "Google.Apis.Calendar.v3.Data.EventAttendee"输入 'System.Collections.Generic.IList'1[Google.Apis.Calendar.v3.Data.EventAttendee]'.

 Dim x As New Google.Apis.Calendar.v3.Data.EventAttendee
            x.Email = "xxccxxxxx@gmail.com"
            x.DisplayName = "xxxxx"
            x.ResponseStatus = "Aproveed"
            Dim y As New Google.Apis.Calendar.v3.Data.EventAttendee
            y.Email = "xxxxxxx@gmail.com"
            y.DisplayName = "suji"
            y.ResponseStatus = "Aproveed"
            Dim attndList As New List(Of EventAttendee)
            attndList.Add(x)
            attndList.Add(y)
            Dim googleCalendarEvent As New [Event]()
            googleCalendarEvent.Attendees = attndList

如果要分配新列表,请执行以下操作。

    Dim googleCalendarEvent As New Google.Apis.Calendar.v3.Data.[Event]()
    googleCalendarEvent.Attendees = New List(Of EventAttendee)
    googleCalendarEvent.Attendees.Add(y)
    googleCalendarEvent.Attendees.Add(x)

相关内容

  • 没有找到相关文章

最新更新