经过几个月的开发,我意识到我的应用程序(仅使用Android 2.1)在我旋转屏幕时崩溃了。我不知道如何调查这个错误。应该是什么原因?谢谢你的建议。这个“警告”会导致错误吗? com.example.app的意外恢复已在com.example.app
中恢复SharedPreferences prefs3 = PreferenceManager.getDefaultSharedPreferences(this);
listener = new SharedPreferences.OnSharedPreferenceChangeListener() {
public void onSharedPreferenceChanged(SharedPreferences prefs, String listpref) {
preferenze();
E/AndroidRuntime( 1269): java.lang.StackOverflowError
E/AndroidRuntime( 1269): at java.util.HashMap.doubleCapacity(HashMap.java:561)
E/AndroidRuntime( 1269): at java.util.HashMap.put(HashMap.java:391)
E/AndroidRuntime( 1269): at java.util.HashSet.add(HashSet.java:95)
E/AndroidRuntime( 1269): at java.nio.charset.Charset.<init>(Charset.java:189)
E/AndroidRuntime( 1269): at com.ibm.icu4jni.charset.CharsetICU.<init>(CharsetICU.java:33)
E/AndroidRuntime( 1269): at com.ibm.icu4jni.charset.CharsetProviderICU.getCharset(CharsetProviderICU.java:62)
E/AndroidRuntime( 1269): at com.ibm.icu4jni.charset.CharsetProviderICU.charsetForName(CharsetProviderICU.java:57)
E/AndroidRuntime( 1269): at java.nio.charset.Charset.forNameInternal(Charset.java:500)
E/AndroidRuntime( 1269): at java.nio.charset.Charset.forName(Charset.java:570)
E/AndroidRuntime( 1269): at com.android.internal.util.FastXmlSerializer.setOutput(FastXmlSerializer.java:292)
E/AndroidRuntime( 1269): at com.android.internal.util.XmlUtils.writeMapXml(XmlUtils.java:180)
E/AndroidRuntime( 1269): at android.app.ApplicationContext$SharedPreferencesImpl.writeFileLocked(ApplicationContext.java:2757)
E/AndroidRuntime( 1269): at android.app.ApplicationContext$SharedPreferencesImpl.access$800(ApplicationContext.java:2510)
E/AndroidRuntime( 1269): at android.app.ApplicationContext$SharedPreferencesImpl$EditorImpl.commit(ApplicationContext.java:2695)
E/AndroidRuntime( 1269): at com.example.app.MainActivity.preferenze(MainActivity.java:3656)
E/AndroidRuntime( 1269): at com.example.app.MainActivity.access$0(MainActivity.java:3632)
E/AndroidRuntime( 1269): at com.example.app.MainActivity$1.onSharedPreferenceChanged(MainActivity.java:2421)
E/AndroidRuntime( 1269): at android.app.ApplicationContext$SharedPreferencesImpl$EditorImpl.commit(ApplicationContext.java:2703)
E/AndroidRuntime( 1269): at com.example.app.MainActivity.preferenze(MainActivity.java:3732)
E/AndroidRuntime( 1269): at com.example.app.MainActivity.access$0(MainActivity.java:3632)
E/AndroidRuntime( 1269): at com.example.app.MainActivity$1.onSharedPreferenceChanged(MainActivity.java:2421)
E/AndroidRuntime( 1269): at android.app.ApplicationContext$SharedPreferencesImpl$EditorImpl.commit(ApplicationContext.java:2703)
E/AndroidRuntime( 1269): at com.example.app.MainActivity.preferenze(MainActivity.java:3732)
E/AndroidRuntime( 1269): at com.example.app.MainActivity.access$0(MainActivity.java:3632)
E/AndroidRuntime( 1269): at com.example.app.MainActivity$1.onSharedPreferenceChanged(MainActivity.java:2421)
E/AndroidRuntime( 1269): at android.app.ApplicationContext$SharedPreferencesImpl$EditorImpl.commit(ApplicationContext.java:2703)
E/AndroidRuntime( 1269): at com.example.app.MainActivity.preferenze(MainActivity.java:3732)
E/AndroidRuntime( 1269): at com.example.app.MainActivity.access$0(MainActivity.java:3632)
E/AndroidRuntime( 1269): at com.example.app.MainActivity$1.onSharedPreferenceChanged(MainActivity.java:2421)
E/AndroidRuntime( 1269): at android.app.ApplicationContext$SharedPreferencesImpl$EditorImpl.commit(ApplicationContext.java:2703)
E/AndroidRuntime( 1269): at com.example.app.MainActivity.preferenze(MainActivity.java:3732)
E/AndroidRuntime( 1269): at com.example.app.MainActivity.access$0(MainActivity.java:3632)
E/AndroidRuntime( 1269): at com.example.app.MainActivity$1.onSharedPreferenceChanged(MainActivity.java:2421)
E/AndroidRuntime( 1269): at android.app.ApplicationContext$SharedPreferencesImpl$EditorImpl.commit(ApplicationContext.java:2703)
E/AndroidRuntime( 1269): at com.example.app.MainActivity.preferenze(MainActivity.java:3732)
E/AndroidRuntime( 1269): at com.example.app.MainActivity.access$0(MainActivity.java:3632)
E/AndroidRuntime( 1269): at com.example.app.MainActivity$1.onSharedPreferenceChanged(MainActivity.java:2421)
E/AndroidRuntime( 1269): at android.app.ApplicationContext$SharedPreferencesImpl$EditorImpl.commit(ApplicationContext.java:2703)
E/AndroidRuntime( 1269): at com.example.app.MainActivity.preferenze(MainActivity.java:3732)
E/AndroidRuntime( 1269): at com.example.app.MainActivity.access$0(MainActivity.java:3632)
E/AndroidRuntime( 1269): at com.example.app.MainActivity$1.onSharedPreferenceChanged(MainActivity.java:2421)
E/AndroidRuntime( 1269): at android.app.ApplicationContext$SharedPreferencesImpl$EditorImpl.commit(ApplicationContext.java:2703)
E/AndroidRuntime( 1269): at com.example.app.MainActivity.preferenze(MainActivity.java:3732)
E/AndroidRuntime( 1269): at com.example.app.MainActivity.access$0(MainActivity.java:3632)
E/AndroidRuntime( 1269): at com.example.app.MainActivity$1.onSharedPreferenceChanged(MainActivity.java:2421)
E/AndroidRuntime( 1269): at android.app.ApplicationContext$SharedPreferencesImpl$EditorImpl.commit(ApplicationContext.java:2703)
E/AndroidRuntime( 1269): at com.example.app.MainActivity.preferenze(MainActivity.java:3732)
E/AndroidRuntime( 1269): a
答案 0 :(得分:4)
问题出在您的MainActivity.java中的preferenze
例程中。
需要查看更多代码才能确定,但看起来您通过在Preferences
回调中修改onSharedPreferenceChanged
而导致无限递归。如果您在回调中编辑首选项,则会再次调用回调,然后再次编辑,再次调用回调等,等等。