There are two specific phrases in the error message, object reference and instance of an object. These concepts are very basic when dealing with OOP languages.
First, an object reference can be thought of a variable in a function or class. This term may also refer to function parameters that expect a specific reference to an object. Initially the value of a variable is NULL until it is set to a value using the '=' operator. Frequently you will have a variable declaration and the '=' operation in the same statement.
The term instance of an object refers to an object that has been created using the syntax new
. When you call new
to initialize an object, an unused memory location is allocated to store a copy of the object until the program ends, or the object goes out of scope and is freed by the garbage collector. At creation time the object properties are defined by the constructor method called to create the object.
Consider this code:
Integer my_int;
my_int = new Integer(5);
In this example, 'my_int' is the object reference to an Integer
object instance being created.
If you try to access 'my_int', before assigning it a reference to an Integer
instance, then you would have the error, "an object reference (my_int) not set to an instance of an object (Integer
)".