我試圖調用應用getSharedPreferences
...如何在應用程序中獲得共享首選項?
public class App extends Application{
public App() {
SharedPreferences prefs = getSharedPreferences(SHARED_PREFERENCES_NAME, Context.MODE_PRIVATE);
}
}
...但我得到了NullPointerException
:
java.lang.NullPointerException: Attempt to invoke virtual method
'android.content.SharedPreferences
android.content.Context.getSharedPreferences(java.lang.String, int)'
on a null object reference
我也嘗試這樣做,得到了同樣的異常:
Context con = getApplicationContext();
我該如何撥打getSharedPreferences
?
http://stackoverflow.com/a/10818234/3395198 –