avatar

Posted by Oerror .com

25 Oct, 2024,

Updated at 22 Dec, 2024

Null Pointer Exception in Object Initialization

Problem: Forgetting to initialize an object before using it. class User: def __init__(self, name): self.name = name def greet(user: User): print(f"Hello, {user.name}") user = None greet(user) Error: AttributeError: 'NoneType' object has no attribute 'name'

We use cookies to enhance your browsing experience, serve personalized ads or content, and analyze our traffic. By clicking "Accept", you consent to our use of cookies. learn more Accept