值不能为空参数名称值 [英] Value Cannot Be Null Parameter Name Value

查看:110
本文介绍了值不能为空参数名称值的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我的一个子程序中出现参数null异常错误:

 如果 MD5Text.Text.Contains(labelX12)然后
                       CheckedListBoxControl1.Items.Add(fs.FullName)
                       lblvirus.Text = CheckedListBoxControl1.Items.Count
                   结束 如果




MD5Text.Text = MD5Reader.ReadToEnd,labelx12是我要比较的字符串.我不知道为什么总是向它提供信息时它会变成空值.我尝试自行解决此问题已有一段时间,并重新搜索了其他站点,这些站点告诉您选中或取消选中一键安全性的安全设置框,但这不能解决我的问题.

这是我特定错误的调用堆栈:

位于System.String.IndexOf(字符串值,Int32 startIndex,Int32计数,StringComparison comparisonType)
   在System.String.Contains(字符串值)
   在C:\ Users \ Admin \ Documents \ Visual Studio 2010 \ Projects \ Final test \ Final test \ Form1.vb:Final_test.Form1.ScanScanner(String dir)中
   在C:\ Users \ Admin \ Documents \ Visual Studio 2010 \ Projects \ Final test \ Final test \ Form1.vb中的Final_test.Form1.starting_scan()
   在System.Threading.ExecutionContext.runTryCode(Object userData)
   在System.Runtime.CompilerServices.RuntimeHelpers.ExecuteCodeWithGuaranteedCleanup(TryCode代码,CleanupCode backoutCode,对象userData)
   在System.Threading.ExecutionContext.Run(ExecutionContext执行上下文,ContextCallback回调,对象状态,布尔ignoreSyncCtx)
   在System.Threading.ExecutionContext.Run(ExecutionContext执行上下文,ContextCallback回调,对象状态)
   在System.Threading.ThreadHelper.ThreadStart()



任何帮助将是非常感谢! c3>,然后是IndexOf.结论是:labelX12null.该错误消息确认了该错误,因为null上的常见错误消息将提示未初始化的变量".

问题是:为什么它是null?为什么要像字符串那样将其称为"label"?我不确定您是否张贴了正确的代码片段.类型为Label的变量将不允许此代码编译.

下次请务必按照Mehdi的建议使用调试器.

-SA


运行调试器,查看if语句的哪一部分给您带来了问题.

如果它是标签控件,则可能希望将labelX12更改为labelX12.Text.


I am getting a argument null exception error in one of my subs:

If MD5Text.Text.Contains(labelX12) Then
                       CheckedListBoxControl1.Items.Add(fs.FullName)
                       lblvirus.Text = CheckedListBoxControl1.Items.Count
                   End If




MD5Text.Text = MD5Reader.ReadToEnd and labelx12 is the string that I am comparing to. I have no idea why it is running into a null value when it is always fed information. I have tried to resolve this issue for some time now on my own and have reasearched other sites that tell you to check or uncheck the security settings box for one click security but that does not solve my issue.

Here is the call stack of my particular error:

at System.String.IndexOf(String value, Int32 startIndex, Int32 count, StringComparison comparisonType)
   at System.String.Contains(String value)
   at Final_test.Form1.ScanScanner(String dir) in C:\Users\Admin\Documents\Visual Studio 2010\Projects\Final test\Final test\Form1.vb:line 155
   at Final_test.Form1.starting_scan() in C:\Users\Admin\Documents\Visual Studio 2010\Projects\Final test\Final test\Form1.vb:line 120
   at System.Threading.ExecutionContext.runTryCode(Object userData)
   at System.Runtime.CompilerServices.RuntimeHelpers.ExecuteCodeWithGuaranteedCleanup(TryCode code, CleanupCode backoutCode, Object userData)
   at System.Threading.ExecutionContext.Run(ExecutionContext executionContext, ContextCallback callback, Object state, Boolean ignoreSyncCtx)
   at System.Threading.ExecutionContext.Run(ExecutionContext executionContext, ContextCallback callback, Object state)
   at System.Threading.ThreadHelper.ThreadStart()



Any help would be great thank you!!

解决方案

Certainly both MD5Text and MD5Text.Text are not null, otherwise you could not observe the call to MD5Text.Text.Contains and then IndexOf. The conclusion is: labelX12 is null. The error message confirms it, as the usual error message on null would suggest "uninitialized variable".

The questions are: why it is null and why it is called "label", as a string is expected? I''m not sure you post right fragment of code. The variable of the type Label would not let this code compile.

Next time always use debugger as Mehdi suggests.

—SA


Run with a debugger and see which part of your if statement is giving you problem.

You might like to change labelX12 to labelX12.Text if it is a label control.


这篇关于值不能为空参数名称值的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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