欢迎您访问 最编程 本站为您分享编程语言代码,编程技术文章!
您现在的位置是: 首页

Object reference not set to an instance of an object.

最编程 2024-02-22 07:21:28
...

Object reference not set to an instance of an object.

简介:         今天从A界面跳转到B界面,并调用B界面中函数的时候,会报错“Object reference not set to an instance of an object.”这个错误,是什么原因呢? 代码中声明了这么一个变量(在从A界面跳转到B界面的过程中都没给KSRQ这个变量赋值)public string KSRQ ;当用到this.KSRQ.Trim() != ""的时候
        今天从A界面跳转到B界面,并调用B界面中函数的时候,会报错“Object reference not set to an instance of an object.”这个错误,是什么原因呢?
代码中声明了这么一个变量(在从A界面跳转到B界面的过程中都没给KSRQ这个变量赋值)
public string KSRQ ;
当用到
this.KSRQ.Trim() != ""
的时候,会报出“Object reference not set to an instance of an object.”这个错误。
解决方法:
public string KSRQ=string.Empty ;
原因:未将对象引用到对象的实例.也就是没有实例化一个对象。当声明了变量,但是没有赋值,仍然为null.用的时候就会报错.