在进行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”的解决方法的更多相关文章

  1. 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 ...

  2. 【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)节点值, ...

  3. [Bug]Object reference not set to an instance of an object.

    引言 今天在客户这儿,由一个问题导致,需求的变化,不得不修改代码,在记录日志中出现该问题. 原因 通过id查找相关信息,没有判断是否为null,集合是否有数据. Object reference no ...

  4. ArcGIS AddIN异常之:object reference not set to an instance of an object

    异常出现在 frmDownload frd = new frmDownload(); frd.ShowDialog(); 在ArcMap中能正常弹出窗体,点击按钮时显示此异常:object refer ...

  5. Azure Sphere–“Object reference not set to an instance of an object” 解决办法

    在开发Azure Sphere应用时,如果出现项目无法编译,出现“Object reference not set to an instance of an object”时,必须从下面两个方面进行检 ...

  6. C# Object reference not set to an instance of an object.

    一.问题 Object reference not set to an instance of an object. (你调用的对象是空的) 二.解决问题 在使用 c# 的查询时,先筛选后在关联其他表 ...

  7. 调试:'Object reference note set to an instance of an object.'

    今天调试代码遇到一个奇怪的问题,每次调试到 var files = new List<string>()这一行代码,总是报错:System.NullReferenceException: ...

  8. 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 ...

  9. WebAdaptor Object reference not set to an instance of an object.

    C:\inetpub\wwwroot\arcgis目录下webAdaptor.config文件内容被清空,从别的地方拷贝一份即可. <?xml version="1.0" e ...

随机推荐

  1. js里生成guid

    function guid() { return 'xxxxxxxx-xxxx-4xxx-yxxx-xxxxxxxxxxxx'.replace(/[xy]/g, function (c) { | , ...

  2. luogu P3226 [HNOI2012]集合选数

    luogu 因为限制关系只和2和3有关,如果把数中2的因子和3的因子都除掉,那剩下的数不同的数是不会相互影响,所以每次考虑剩下的数一样的一类数,答案为每类数答案的乘积 如果选了一个数,那么2的因子多1 ...

  3. 转载:elasticsearch入门篇

    转自:https://www.cnblogs.com/hello-shf/p/11543408.html elasticsearch入门篇   elasticsearch专栏:https://www. ...

  4. Spring IOC的简单实现

    简单的说,Spring就是通过工厂+反射将我们的bean放到它的容器中的,当我们想用某个bean的时候,只需要调用getBean("beanID")方法即可. 原理简单说明: Sp ...

  5. 全局捕获异常(适用于SpringMvc,SpringBoot项目)

    @ControllerAdvice 是controller的一个辅助类,最常用的就是作为全局异常处理的切面类.约定了几种可行的返回值,可以返回String字符串,也可以返回ModelAndView,也 ...

  6. 重装系统win10教程(激活系统、office下载、分区)

    看见有很多小白不知道怎么重装系统,故而在此特别做一个详细教程,大家按照教程做就可以了,也不用去电脑店浪费钱重装系统,在此安装的win10系统,现在win10系统已经是最好的Windows系统了,如果没 ...

  7. Linux 的帐号与群组:有效与初始群组、groups, newgrp

    关于群组: 有效与初始群组.groups, newgrp 认识了帐号相关的两个档案 /etc/passwd 与 /etc/shadow 之后,您或许还是会觉得奇怪, 那么群组的设定档在哪里?还有,在 ...

  8. 第一篇、Python入门

    一 编程与编程语言 python是一门编程语言,作为学习python的开始,需要事先搞明白:编程的目的是什么?什么是编程语言?什么是编程? 编程的目的: #计算机的发明,是为了用机器取代/解放人力,而 ...

  9. python中import cv2遇到的错误及安装方法

    参考链接:https://blog.csdn.net/yuanlulu/article/details/79017116 从x86_64 + ubuntu18.04 + python3.5中impor ...

  10. MST-kruskal ElogE+V

    hdu 1233 #include<stdio.h> #include<algorithm> using namespace std; struct dis { int a, ...