Magento: Fatal error: Call to a member function setSaveParametersInSession() on a non-object

Scenario

I was creating a module. I already had one Grid displayed in admin. The Grid was being displayed by a Block class, for example: MyNamespace_MyModule_Block_Adminhtml_MyModule
Now, I had to display another Grid using a new Block class. Let’s say, I created a new Block class: MyNamespace_MyModule_Block_Adminhtml_MyNewGrid

I just copied code from MyNamespace_MyModule_Block_Adminhtml_MyModule and copied it to MyNamespace_MyModule_Block_Adminhtml_MyNewGrid class.

MyNamespace_MyModule_Block_Adminhtml_MyModule


class MyNamespace_MyModule_Block_Adminhtml_MyModule extends Mage_Adminhtml_Block_Widget_Grid_Container
{
  public function __construct()
  {
    $this->_controller = 'adminhtml_mymodule';
    $this->_blockGroup = 'mymodule';
    $this->_headerText = Mage::helper('mymodule')->__('Module Data');   
    parent::__construct(); 
  }
}

MyNamespace_MyModule_Block_Adminhtml_MyNewGrid


class MyNamespace_MyModule_Block_Adminhtml_MyNewGrid extends Mage_Adminhtml_Block_Widget_Grid_Container
{
  public function __construct()
  {
    $this->_controller = 'adminhtml_mymodule';
    $this->_blockGroup = 'mynewgrid';
    $this->_headerText = Mage::helper('mymodule')->__('Module Data New');   
    parent::__construct(); 
  }
}

Cause

The main mistake over here was the confusing naming for controller and blockGroup.

$this->_controller = This is not the controller class name. It is actually your Block class name.
$this->_blockGroup = This is your module’s name.

Solution

Hence, I updated my new grid class in the following way and the problem was solved. See the change in controller and blockGroup from the previous code.

MyNamespace_MyModule_Block_Adminhtml_MyNewGrid


class MyNamespace_MyModule_Block_Adminhtml_MyNewGrid extends Mage_Adminhtml_Block_Widget_Grid_Container
{
  public function __construct()
  {
    $this->_controller = 'adminhtml_mynewgrid';
    $this->_blockGroup = 'mymodule';
    $this->_headerText = Mage::helper('mymodule')->__('Module Data New');   
    parent::__construct(); 
  }
}

Hope this helps. Thanks.