Android SharedPreferences NullPointerException on getSharedPreferences
<p>I'm trying to create a single class which will deal with storing and retrieving two user settings 'radius' and 'cluster'.</p>

<p>Upon loading the 'Settings' activity I get a null pointer exception.</p>

<p><strong>Snippet from the user settings:</strong></p>

<pre><code>    storage = new Persistence();
    radius = (EditText) findViewById(R.id.etRadius);        
    radius.setText(String.valueOf(storage.getRadius()));  &lt;-- Problem
</code></pre>

<p><strong>Class to deal with persistence:</strong> </p>

<pre><code>public class Persistence extends Activity { 

    private static final String PREFERENCES = "tourist_guide_preferences";
    private SharedPreferences settings;
    private SharedPreferences.Editor editor;

    protected void onCreate(Bundle savedInstanceState)
    {
        super.onCreate(savedInstanceState);
        settings = getSharedPreferences(PREFERENCES, 0);
        editor = settings.edit();
    }

    public int getRadius()
    {
        return settings.getInt("radius", 2000);
    }

    public int getClusterSize()
    {
        return settings.getInt("cluster", 50);
    }

    public void setRadius(int radius)
    {
        editor.putInt("radius", radius);
        editor.commit();
    }

    public void setClusterSize(int size)
    {
        editor.putInt("cluster", size);
        editor.commit();        
    }   
}
</code></pre>
