How to fix null pointer in PreferenceActivity?
<p>In Android I suddenly get an error </p>

<pre><code>Caused by: java.lang.NullPointerException: Attempt to invoke virtual method 'void android.preference.Preference.setOnPreferenceClickListener(android.preference.Preference$OnPreferenceClickListener)' on a null object reference
    at com.impyiablue.stoxx.UserSettingActivity.onCreate(UserSettingActivity.java:32)
    at android.app.Activity.performCreate(Activity.java:5977)
    at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1105)
    at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2258)
    at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2365) 
    at android.app.ActivityThread.access$800(ActivityThread.java:148) 
    at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1283) 
    at android.os.Handler.dispatchMessage(Handler.java:102) 
    at android.os.Looper.loop(Looper.java:135) 
    at android.app.ActivityThread.main(ActivityThread.java:5272) 
    at java.lang.reflect.Method.invoke(Native Method) 
    ... 
                                                                          at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:704) 
</code></pre>

<p>in this piece of code: </p>

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

    private Preference myPreference;
    MainActivity.MyCallBack callBack;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);

        // replaced on 5.1.2016
        // http://stackoverflow.com/questions/6822319/what-to-use-instead-of-addpreferencesfromresource-in-a-preferenceactivity
        //addPreferencesFromResource(R.xml.preferences);
        getFragmentManager().beginTransaction().replace(android.R.id.content, new MyPreferenceFragment()).commit();

        myPreference = findPreference("reset");
        myPreference.setOnPreferenceClickListener(new Preference.OnPreferenceClickListener() {
             public boolean onPreferenceClick(Preference arg0) {
             ...
</code></pre>

<p>and the <code>preferences.xml</code> file looks as follows: </p>

<pre><code>&lt;?xml version="1.0" encoding="utf-8"?&gt;
&lt;PreferenceScreen xmlns:android="http://schemas.android.com/apk/res/android"&gt;
    &lt;EditTextPreference android:title="Your Name"
        android:key="username"
        android:summary="Please provide your username"&gt;&lt;/EditTextPreference&gt;
    &lt;CheckBoxPreference android:title="Application Updates"
        android:defaultValue="false"
        android:summary="This option if selected will allow the application to check for latest versions."
        android:key="applicationUpdates" /&gt;

    &lt;Preference
        android:key="reset"
        android:title="Reset database"
        android:summary="This will remove every entry in the database"
         /&gt;
&lt;/PreferenceScreen&gt;
</code></pre>

<p>It worked before (I cannot specify before what time). I just want to have an item 'reset' in my settings which will delete the database of the app. The method <code>findPreference</code> is striked through (implying it is some outdated code, without any clue how to 'fix' it).</p>

<p>How can I fix this null pointer exception?</p>