Posts

Showing posts with the label excepption

Null Reference Exception

  What is a Null Reference Exception: A Null Reference Exception (often called a NullPointerException in some languages like Java) is a common runtime error in programming that occurs when your code tries to use an object reference that has not been initialized (i.e., it points to null or None ). What is a "null reference"? A null reference means a variable exists but does not point to any object in memory . It’s like having a remote control (the reference) that isn’t paired to any TV (the object). Trying to use it does nothing—or worse, causes an error. What causes a Null Reference Exception? A Null Reference Exception happens when you try to: Access a method or property on a null object. Index into a null array or list. Pass a null object to a method expecting a valid one. Dereference a null pointer. Example in C#: string name = null; int length = name.Length; // NullReferenceException here You're trying to access . Length on name , w...