Null Pointer when trying to dynamically disable a preference
<p>I am getting a null pointer exception on <code>mPreference = (Preference)...</code> in the following code (i.e. with debugger on, <code>mPreference</code> shows null; NB key is non-null, I can substitute with a literal and it still gives me the same exception):</p>

<pre><code>public class SettingsManager extends PreferenceActivity {

    private Preference mPreference;
    private static boolean toggle;

    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        // Load the XML preferences file
        addPreferencesFromResource(R.xml.preferences);
    }

    public void setPrefEnabled(Context context, String key, String enabled) {
        if (enabled.contentEquals("true")) {
            toggle = true;
        } else {
            toggle = false;
        }
        mPreference = (Preference) getPreferenceScreen().findPreference(key);
        mPreference.setEnabled(toggle);
    }
}
</code></pre>

<p>The class is being called by the following code, in the <code>applySettings</code> method of a class where <code>settingsManager</code> is instantiated in the constructor:</p>

<pre><code>public class ConfigurationSetter {

    private static Context mContext;
    private static SettingsManager settingsManager;

    public ConfigurationSetter(Context context) {
        mContext = context;
        settingsManager = new SettingsManager();
    }

    private static void applySettings(Context context, String key,
            String value, String enabled) {
        settingsManager.setPrefEnabled(mContext, key, enabled);
    }
}
</code></pre>

<p>I've been scratching my head on this but may be a little too tired to figure it out on my own. Any help is appreciated.</p>

<p>Related to this problem, I <a href="http://stackoverflow.com/questions/10423709/are-intents-required-to-persist-preference-state-in-a-headless-activity">asked a question here</a> about whether intents are the required instantiater for this activity.</p>
