代碼:http://pastebin.com/sh5TKhVv 我已經coppied從書這種代碼,我沒有改變任何東西,但它在線路96這個錯誤和192該方法適用於()是未定義的類型SharedPreferences.Editor
preferencesEditor.apply(); --> The method apply() is undefined for the type SharedPreferences.Editor
代碼:http://pastebin.com/sh5TKhVv 我已經coppied從書這種代碼,我沒有改變任何東西,但它在線路96這個錯誤和192該方法適用於()是未定義的類型SharedPreferences.Editor
preferencesEditor.apply(); --> The method apply() is undefined for the type SharedPreferences.Editor
SharedPreferences.Editor.apply();在API LEVEL 9加入。如果您使用的是從9較低的版本,然後使用SharedPreferences.Editor. commit()保存所有chnages與SharedPreferences
shared_preferences= PreferenceManager.getDefaultSharedPreferences(getApplicationContext());
editor =shared_preferences.edit();
editor.putString("test","Done");
editor.commit();
我有同樣的問題儘管我使用的是API LEVEL 17.
此行解決了我的問題:
SharedPreferences.Editor.commit();