- Home /
NullReferenceException on an assignment line
Hi everyone.
I am confused because I am just assigning a null to my instance bug I am receiving NullReferenceException on the following line:
128 catch (Exception ex)
129 {
130 device = null;
131 }
The content of the exception is:
NullReferenceException: Object reference not set to an instance of an object
SampleScript.OnRawFrame (System.Int32 nSeq, System.Int32[] data) (at Assets/SampleScript.cs:130)
BioSignalPlux.CSharp.BaseDevice.Loop () (at Assets/BioSignalPlux.cs:180)
SampleScript.Update () (at Assets/SampleScript.cs:80)
And it happens randomly after 1 minute my code runs. Please help me figure out the problem.
Answer by RedDeCipher · Jan 15, 2018 at 10:45 PM
It's because NullReferenceException is given when you try to use a variable that is null which means no value assigned. When you make it null and try to use it, it will give you that error.
Thank you! I know what is the meaning of this exception. For your information. if you read the line 130, I am not using it. I am only assigning.
Are you sure anything else also not using it? $$anonymous$$aybe something else was using it when you assigned it as null.
In that case, the exception would be different.
Your answer
Follow this Question
Related Questions
Assignment working in Update() but not in Start()? 1 Answer
NullReferenceException when sending message to another object...really stumped. 1 Answer
Problem with Null Reference Exeption??:/ 1 Answer
NullReferenceException: Object reference not set to an instance of an object 0 Answers
How to setup code so it can recompile without null exception while running 1 Answer