Fatal Error: Uncaught Error: Calling a member of the getId () function on null in

I am new to Magento.
I'm trying to configure a configurable product using this link

https://popatkaran.wordpress.com/2015/07/24/create-configurable-products-programically-magento/

but when i try to run the file, i get this error

Fatal Error: Uncaught Error: Calling a member function getId () on null
in
C: xampp htdocs magento app code core Mage Catalog Template Product Type Configurable.php: 284
Stack trace: # 0

Can someone help me, please?
Thank you!