I save config with SharedPreferences
and load it in class extends Services.
But error appear when I try get values of config, error like:
Unable to instantiate service kr.co.composer.callrecord.recorder.CallRecordService: java.lang.NullPointerException
at line:
final SharedPreferences mSharedPreference= PreferenceManager.getDefaultSharedPreferences(getApplicationContext());
In layout Configuration
I save a EditText:
final SharedPreferences prefs = PreferenceManager
.getDefaultSharedPreferences(this);
serverUrl.setText(prefs.getString("autoSave", ""));
serverUrl.addTextChangedListener(new TextWatcher() {
@Override
public void onTextChanged(CharSequence s, int start, int before,
int count)
{
}
@Override
public void beforeTextChanged(CharSequence s, int start, int count,
int after)
{
}
@Override
public void afterTextChanged(Editable s)
{
prefs.edit().putString("autoSave", s.toString()).commit();
}
});
And in the other class, I want to get this values by this code:
public class CallRecordService extends Service {
final SharedPreferences mSharedPreference= PreferenceManager.getDefaultSharedPreferences(getApplicationContext());
@Override
public void onCreate() {
serverURL =(mSharedPreference.getString("autoSave", ""));
}
}