致命错误:在非对象[重复]上调用成员函数setName()

This question already has an answer here:

I created one module in magento Local->Vehicle->Bike

In controller i write code for model:

$model_obj = Mage::getModel('bike/honda'); $model_obj->setName( $name );

It gives error like

Fatal error: Call to a member function setName() on a non-object in /opt/lampp/htdocs/magento/app/code/local/Vehicle/Bike/controllers/IndexController.php on line 40

</div>

Your call

Mage::getModel('bike/honda')

returns null. That's why $model_obj is a non-object and you get that error.

There is no function named setName() in the model bike/honda or try to use $this->model_obj->setName( $name );