I'm trying to create a single class which will deal with storing and retrieving two user settings 'radius' and 'cluster'.
Upon loading the 'Settings' activity I get a null pointer exception.
Snippet from the user settings:
storage = new Persistence();
radius = (EditText) findViewById(R.id.etRadius);
radius.setText(String.valueOf(storage.getRadius())); <-- Problem
Class to deal with persistence:
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();
}
}