A bug Story - "Object reference not set to an instance of an object "

                 

Ideally when this messege is thrown by GC or GCScript, or any (other software ) , as a user you need to know it's a bug that needs to be fixed . But what it means would be helpful for the user to find out what exactly did he do wrong or may be how to fix it .It simply means "I don't know the value" , this error is thrown when a value of ‘null' is assigned to a variable or property. And the code has not been checked for such errors. How could  this happen?  if a value assigned to a variable  is not returning anything but that would be considered as null. ‘null' means it does not exist. It does not mean ‘0' .'0' is a value. But null is not. That is how one find out if  a value is assigned or not, so by checking if ' X!=null', the programmer can find out if a value is assigned to a variable or not .

It would be good to know where it comes from. Let's understand the background.

Each and every feature in GC is an object of a Class

For eg: Point is Class , point01 is an instance or object  of that class.  So what's a Class ? it's a way of organizing/grouping  the data. For eg: Homo Sapiens is  a class, but ‘John' is an instance of that class . So the instance can have different value and attributes that differentiate from another instance. But would have similarities that club them together as a group and share some of those attributes.

There are lot of articles one could find on it or any object oriented programming book would explain it how.

In simple terms ,there is data expressed in terms of  variables , and there  are operations that can be performed on these data. So in general these needs to be used and accessed by the class itself and by other class that can perform operations

On these data. Let's call the some of the operations are expressed in terms of functions. So in General a structure of a class Would be look like

 

Class homoSapien{/*variables  String name ; Int Age;/* functions that can give information on homosapienPublic getName ();Public setName();Private setAge();Private getAge(); / John don't want everybody to know his age so he keep it private J.}

 Public and Private helps to organize the data again. If its Private it can not be accessed by other classes.

For more details and refer any object oriented programming book.

Once the class is created , it gives us a way of organizing the information. We have not used it yet.

For using it we create an object.

homoSapien John;

 

This means that the john is variable of type homoSapien. So far we have not allocated any values to it .

Now to store the value of this variable we need to assign memory (space) to it. How do we know how to do it .

 

John = new homoSapien();  // this assigns space based on the object type homoSapien.

Not assigning the space and later on if that object is used could again cause it to take the value null.

As there was no space allocated, the values assigned would not be stored.

Or other operations again could overwrite the memory or set it back to null.

After which the john can be assigned name . age and can be used any where else and filled with values.

Now how that is effecting your GC example, if particular function returning null, it could throw the error. or when a feature fails, and the proeprty of which is asinged to another it could through the error. or if the user tries to access

a feature that was never created at all, it could throw simialr error. Look out for it . Again, so if you see this error , then pls get back to us with the error report

Ah, now that was some information .... I hope useful for you .

Now its time for me to end my week  .... TGIF

Monika
Parents Comment Children
No Data