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

configurationerror

I have added a menu option in the system | configuration panel but when I click on the link I get the below error

Fatal error: Call to a member function toOptionArray() on a non-object in /Users/myName/Sites/magentoDevTest/app/code/core/Mage/Adminhtml/Block/System/Config/Form.php on line 463

I was hoping to try and solve this problem by looking at the core code, but I have not been successful with that approach, Ive looked around online but cant finds anything that has helped me

My system.xml file is

<config>
<tabs><!--creates tabs on the adminhtml page-->
    <training translate="label" module="training">
        <label>Training</label><!--creates a tab with the title of Training (a menu's title is called title a tabs title is called training)-->
        <sort_order>102</sort_order><!--the order of the tab-->
    </training>
</tabs>

<sections><!--creates a section on under the tab called animal-->
    <training translate="label" module="training"><!--maps to <config><tabs><training> in this xml doc (system.xml)-->
        <label>Animal</label><!--names the bar animal-->
        <sort_order>10</sort_order><!--order of the bar-->
        <tab>training</tab><!--maps to <config><tabs><training> must be the same casing as the tab it maps to-->
        <show_in_default>1</show_in_default><!--shows this tab in a website scope-->
        <show_in_website>1</show_in_website><!--shows this tab in a website scope-->
        <show_in_store>1</show_in_store><!--shows this tab in a website scope-->
        <groups><!--sets the blue bar in the main content area of the page-->
            <general translate="label" module="training">
                <label>General Settings</label><!--sets the blue bars title-->
                <sort_order>10</sort_order><!--sets the order of the bar-->
                <show_in_default>1</show_in_default><!--shows this tab in a website scope-->
                <show_in_website>1</show_in_website><!--shows this tab in a website scope-->
                <show_in_store>1</show_in_store><!--shows this tab in a website scope-->
                <fields><!--sets which fields are available in the "general" bar-->
                    <recommendation translate="label comment" module="training">
                        <label>Recommendation</label><!--creates a option called recommentaion-->
                        <frontend_type>text</frontend_type><!--What does this do?-->
                        <sort_order>10</sort_order><!--sets the sort order of this field-->
                        <show_in_default>1</show_in_default><!--shows this tab in a website scope-->
                        <show_in_website>1</show_in_website><!--shows this tab in a website scope-->
                        <show_in_store>1</show_in_store><!--shows this tab in a website scope-->
                        <depends><!--This refers to <show_recommendations> node and is required for <show_recommendations> to be displayed-->
                            <show_recommendations>1</show_recommendations>
                        </depends>
                        <comment><![CDATA[<strong>This</strong> is a comment]]></comment><!--what does this do?-->
                    </recommendation>
                    <show_recommendation translate="label" module="training">
                        <label>Display Recommendations</label><!--creates a option called display recommentaion-->
                        <frontend_type>select</frontend_type><!--whats this do?-->
                        <source_model>training/system_config_source_show</source_model><!--sets the source model tha will be used?-->
                        <sort_order>20</sort_order><!--sets the order-->
                        <show_in_default>1</show_in_default><!--shows this tab in a website scope-->
                        <show_in_website>1</show_in_website><!--shows this tab in a website scope-->
                        <show_in_store>1</show_in_store><!--shows this tab in a website scope-->
                        <tooltip>More Javascript in use!</tooltip><!--shows text on hover-->
                    </show_recommendation>
                </fields>
            </general>
        </groups>            
    </training>
</sections>

===EDIT===

config.xml

    <global>
    <models>
        <training><!--Namespace name-->
            <class>Training_Animal_Model</class><!--File path to the model directory-->
            <resourceModel>training_animal_resource</resourceModel><!--maps to resource model node-->
        </training>
     ...

Best Answer

Most probably this is the issue :

<source_model>training/system_config_source_show</source_model>

When declaring a source model for a field in system.xml, Magento will try to retrieve the options for the field by calling:

Mage::getModel('source model here')->toOptionArray();

So in your case it tries :

Mage::getModel('training/system_config_source_show')->toOptionArray();

and Mage::getModel('training/system_config_source_show') returns null. Make sure the model exists.