' System.ArgumentNullException'错误 [英] 'System.ArgumentNullException' error

查看:88
本文介绍了' System.ArgumentNullException'错误的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

美好的一天,

我对编程非常陌生,并且遇到了我正在努力找出的错误.我试图从Outlook中拉出联系人并以组合弓的形式显示它们,但出现此错误,"System.ArgumentNullException"在运行时出现以下代码:

I am very new to programming and have an error I am struggling to figure out. I am trying to pull contacts from Outlook and display them in a combo bow but get this error, 'System.ArgumentNullException' comes up at run time for the following code:

        Dim folderContacts As Microsoft.Office.Interop.Outlook.MAPIFolder = outApp.ActiveExplorer() _
            .Session.GetDefaultFolder(Microsoft.Office.Interop.Outlook.OlDefaultFolders _
            .olFolderContacts)
        Dim searchFolder As Microsoft.Office.Interop.Outlook.Items = folderContacts.Items
        Dim counter As Integer = 0
        For Each foundContact As Microsoft.Office.Interop.Outlook.ContactItem In searchFolder
            With MessageSend.cmbxMsgName
                .Items.Add(foundContact.Email1Address)
                counter += 1
            End With
        Next

调试显示错误与

.Items.Add(foundContact.Email1Address)

请帮助.我知道它不能传递空值,但是如何停止它或将其更改为停止?

Please help. I know it cannot pass a null value but how do I stop this or change it to stop?

推荐答案

Debug显示错误与;
Debug shows the error is with 
.Items.Add(foundContact.Email1Address)

请帮助.我知道它不能传递空值,但是如何停止它或将其更改为停止?

Please help. I know it cannot pass a null value but how do I stop this or change it to stop?

您需要确保该值不为null.您应该检查发生错误的代码行,并确定引起该问题的变量.从您的代码看来,可能性要么在 MessageSend . cmbxMsgName . 项目 foundContact . 电子邮件1地址.

You need to make sure that the value is not null.    You should examine the line of code where the error occurs, and determine which variable is causing the problem.  It appears from your code that the possibilities are either in MessageSend.cmbxMsgName.Items or foundContact.Email1Address. 

我认为MessageSend.cmbxMsgName可能是一个表单控件,如果是,则.Items不能为空.另外, foundContact不能为空,否则将退出循环,因此最可能的原因是该联系人没有电子邮件地址. 您需要先检查联系人是否具有电子邮件地址,然后才能使用它.

I think that MessageSend.cmbxMsgName might be a form control, and if so then .Items cannot be nothing. Also,  foundContact cannot be nothing or the loop would have exited, so the most likely cause is that the contact does not have an email address.  You need to check that the contact has an email address before attempting to use it.


这篇关于' System.ArgumentNullException'错误的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆