Asp.net 空引用异常-即使存在新关键字
代码如下:Asp.net 空引用异常-即使存在新关键字,asp.net,vb.net,google-api,Asp.net,Vb.net,Google Api,代码如下: 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.
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)
它将错误显示为
无法强制转换类型为的对象
输入'Google.api.Calendar.v3.Data.EventAttendee'
'System.Collections.Generic.IList`1[Google.api.Calendar.v3.Data.EventAttendee]'
如果您想分配新列表,请执行以下操作
Dim googleCalendarEvent As New Google.Apis.Calendar.v3.Data.[Event]()
googleCalendarEvent.Attendees = New List(Of EventAttendee)
googleCalendarEvent.Attendees.Add(y)
googleCalendarEvent.Attendees.Add(x)
它将抛出以下错误:
无法将“Google.api.Calendar.v3.Data.EventAttendee”类型的对象强制转换为“System.Collections.Generic.IList”
1[Google.api.Calendar.v3.Data.EventAttendee]。`@Bjørn Roger Kringsjå:这是你的工作吗?检查你是否提供了我问题的答案?是的。副本是正确的。属性Attenders
未实例化。您需要创建一个新实例googleCalendarEvent.Attendes=新列表(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)