App Is Crashing With Shared Preferences
I'm trying to set drawables on right in edittext with shared preferences, but I don't know where I went wrong, it's crashing on start of the activity. I want that it changes the dr
Solution 1:
You are calling a method before its available.
Put this on class level
SharedPreferences menaPref;
Editor editor;
and in onCreate use this
menaPref = getApplicationContext().getSharedPreferences("MyPrefs", MODE_PRIVATE);editor = menaPref.edit();
Solution 2:
it is only an idea, but try to move the
menaPref = getApplicationContext().getSharedPreferences("MyPrefs", MODE_PRIVATE);
to the onCreate.
Solution 3:
getApplicationContext() is available after onCreate or onStart but not this way. please init your sharedPreferences in onCreate.
Like this
SharedPreferences menaPref;
Editor editor;
publicvoidonCreate(..){
menaPref = getApplicationContext().getSharedPreferences("MyPrefs", MODE_PRIVATE);
editor = menaPref.edit();
}
Post a Comment for "App Is Crashing With Shared Preferences"