Click here to Skip to main content
15,662,426 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
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...

C#
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;
        }
Posted

1 solution

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.
 
Share this answer
 
Comments
Nashprem 28-Jul-10 3:14am    
1. Actually I already define 'ref' to cSN, sw12, and errdec before using it but if i take the 'ref' out, it popping out an error 'Arguments must with the 'ref' keyword'

2. The configXML is declare in
public ConfigXML.ConfigINI configXML = new ConfigXML.ConfigINI();
Sandeep Mewara 28-Jul-10 3:47am    
Well then you should had posted the method that i asked for. Didn't DEBUG helped you?
Nashprem 28-Jul-10 3:56am    
The test1_1.Initialise is declared wit "public string Initialise(int deviceIDX, byte sSlot, ConfigINI cXML, ref byte[] cSN, ref string sProgress, ref int lProcess, ref byte[] sw12, ref string errdes);"
I Debug and it came out the same error.. NullReferenceException was handled.
Sandeep Mewara 28-Jul-10 4:27am    
Obviously it would be same error even in debug. But debug would lead you directly to the line of issue!

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900