错误“Object reference not set to an instance of an object”的解决方法
在进行unity游戏制作的C#代码编写时,会遇到“NullReferenceException: Object reference not set to an instance of an object”这样的错误提示。错误的意思翻译过来是“未将对象引用到对象的实例”,意思就是声明了对象,却没有给它赋值,导致运行的时候依旧是null值。
个人遇到这个情况是在获取控件的时候,原代码为: “text1 = GetControl(“Content/Main/Body/Mail1/Text”);” 出错的原因很简单,获取控件的时候遗漏了初始路径并使用了错误的控件名。
这里要提醒大家的是,如果是从零开始获取的控件,一定要记得从最初始的路径开始获取,直接点说就是面板里最上面的控件。一定要核对控件名的拼写,确保正确。这类错误百分五十都是因为拼写控件名错误导致的。而且要注意的是,控件名称不要使用中文符号,类似“(”、“)”的,都无法获取。最简单保险的方法就是获取控件的时候直接从面板里复制控件名称,这样最不容出错。
希望大家都能细心一点,不要为了解决这类由于粗心导致的失误而浪费过多时间。
错误“Object reference not set to an instance of an object”的解决方法的更多相关文章
- Visual Studio 2015打开ASP.NET MVC的View提示"Object reference not set to an instance of an object"错误的解决方案
使用Visual Studio 2013打开没有问题,但Visual Studio 2015打开cshtml就会提示"Object reference not set to an insta ...
- 【Azure API 管理】使用APIM进行XML内容读取时遇见的诡异错误 Expression evaluation failed. Object reference not set to an instance of an object.
问题描述 使用APIM,在 Inbound 中对请求的Body内容进行解析.客户端请求所传递的Request Body为XML格式,需要从Request Body中解析出多个(Element)节点值, ...
- [Bug]Object reference not set to an instance of an object.
引言 今天在客户这儿,由一个问题导致,需求的变化,不得不修改代码,在记录日志中出现该问题. 原因 通过id查找相关信息,没有判断是否为null,集合是否有数据. Object reference no ...
- ArcGIS AddIN异常之:object reference not set to an instance of an object
异常出现在 frmDownload frd = new frmDownload(); frd.ShowDialog(); 在ArcMap中能正常弹出窗体,点击按钮时显示此异常:object refer ...
- Azure Sphere–“Object reference not set to an instance of an object” 解决办法
在开发Azure Sphere应用时,如果出现项目无法编译,出现“Object reference not set to an instance of an object”时,必须从下面两个方面进行检 ...
- C# Object reference not set to an instance of an object.
一.问题 Object reference not set to an instance of an object. (你调用的对象是空的) 二.解决问题 在使用 c# 的查询时,先筛选后在关联其他表 ...
- 调试:'Object reference note set to an instance of an object.'
今天调试代码遇到一个奇怪的问题,每次调试到 var files = new List<string>()这一行代码,总是报错:System.NullReferenceException: ...
- Spine用于Timeline(NullReferenceException: Object reference not set to an instance of an object pine.Unity.Editor.AnimationReferenceAssetEditor.OnInspectorGUI ())
报错信息:Spine.Unity.Editor.AnimationReferenceAssetEditor.OnInspectorGUI () (at Assets/Extention/Spine/E ...
- WebAdaptor Object reference not set to an instance of an object.
C:\inetpub\wwwroot\arcgis目录下webAdaptor.config文件内容被清空,从别的地方拷贝一份即可. <?xml version="1.0" e ...
随机推荐
- 关于redis的几件小事(六)redis的持久化
1.redis持久化的意义 redis持久化的意义,在于 故障恢复 . 如果没有对数据进行持久化,那么如果redis遇到灾难性的故障,就会丢失所有的数据. 如果通过redis的持久化机制将数据持久化到 ...
- mac终端解决很多系统自带命令找不到问题
node安装提示npm command not found 1.打开终端 2.输入命令如下: touch~/.bash_profile (创建.bash_profile文件,-表示在-目录下,.表示 ...
- 键盘事件 Ctrl+p 模拟(vue)
方法定义 // 打印页面 printpage(myDiv) { // myDiv 为打印对象的id名 var newstr = document.getElementById(myDiv).inner ...
- 记一次生产环境presto删表失败的问题
场景,开发用java程序连接presto创建一个表,这个表在hdfs的权限为: 然后用presto去删除这个表 报错,没有权限删除,查看上一级目录权限,发现权限正常 直连hive删表 发现正常. 然后 ...
- java多线程ExecutorService
1.new Thread的弊端 执行一个异步任务你还只是如下new Thread吗? new Thread(new Runnable() { @Override public void run() { ...
- linux图形界面安装
1.问题现象 1.1 startx命令不可用 [root@linuxtest2 ~]# startx 1.3 init 5无法执行完成 [root@linuxtest2 ~]#init 5 2.问题原 ...
- tornada-数据库
数据库 torndb安装 连接初始化 执行语句 execute execute_rowcount 查询语句 get query 与Django框架相比,Tornado没有自带ORM,对于数据库需要自己 ...
- Markdown,让你的代码高亮起来
当你的审美提高或者习惯了Linux下的黑色代码高亮,已经不满足与博客园原有的代码高亮,那么这篇博客就是你的选择. 代码块高亮 代码块Highlight /* 使用了Monokai Sublime的黑色 ...
- selenium-Xpath使用方法
01:什么是Xpath Xpath是一门xml文档中查找信息的语言,Xpath可用来在xml文档中对元素和属性进行遍历,主流的浏览器都支持xpath,因为HTML页面在DOM中表示xhtml文档 xp ...
- 【鸽】poj3311 Hie with the Pie[状压DP+Floyd]
题解网上一搜一大坨的,不用复述了吧. 只是觉得网上dp方程没多大问题,但是状态的表示含义模糊.不同于正常哈密顿路径求解,状态表示应当改一下. 首先定义一次移动为从一个点经过若干个点到达另一个点,则$f ...