未处理NullReferenceException [英] NullReferenceException was unhandled

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

问题描述

在那......
我是C#的新程序员.我在NullReferenceException未处理中要解决的错误.
该脚本如下所示.错误发生在结果= test1_2.Initialise"行中.
谁能指导我如何解决这个未解决的问题... ??:confused:
提前谢谢...

Hie there...
I am new programmer for C#. I have an error to solve in NullReferenceException was unhandled.
The script is as below... The error occur in the line ''result = test1_2.Initialise''..

Can anyone guide me how to solve this unhandled problem...??:confused:
Thanks in advance...

private void StartReadInlay2()
        {
            byte[] cSN = new byte[8];
            byte[] sw12 = new byte[2];
            string strsw12 = "", errdes = "", result = "";
            test1_2 = new Initialisation();
            test1_2.logmode = Convert.ToInt32(ConfigurationSettings.AppSettings["LogMode"]);
            test1_2.iChipType = GetChipType(lblChipType.Text.Trim());
            //--initialise test
            result = test1_2.Initialise(1, configXML.fnSamSlot, configXML, ref cSN, ref sProgress1_2, ref lProcess1_2, ref sw12, ref errdes);
            scSN1_2 = Hex.ToHexString(test1_2.chipID);
            strsw12 = Hex.ToHexString(sw12);
            if (strsw12.Equals("0000"))
                errInlay1_2 = result.ToString();
            else
                errInlay1_2 = result.ToString() + strsw12;
            lProcess1_2 = 2;
            if(!errInlay1_2.Equals(""))
                StatusInlay1_2 = false;
            else
                StatusInlay1_2 = true;
        }

推荐答案

result = test1_2.Initialise(1,configXML.fnSamSlot,configXML,ref cSN,ref sProgress1_2,ref lProcess1_2,ref sw12 ,请参阅errdes);

1.您为cSN,sw12定义了"ref",看起来好像没有初始化.您应该在使用前进行此操作.
2. configXML已经是参数之一,那么为什么还要发送configXML.fnSamSlot?

在发生错误的test1_2.Initialise()方法中发布您的行.当然,您正在尝试访问空"变量.一个简单的调试可以告诉您它在哪里.
result = test1_2.Initialise(1, configXML.fnSamSlot, configXML, ref cSN, ref sProgress1_2, ref lProcess1_2, ref sw12, ref errdes);

1. You defined ''ref'' to cSN, sw12 that doesn''t look initialized. You should do that before using.
2. configXML is already one of the parameter, then why sending configXML.fnSamSlot too?

Post your line in test1_2.Initialise() method where the error is happening. Surely you are trying to access a variable that is ''null''. A simple DEBUG can tell you where it is.


这篇关于未处理NullReferenceException的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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