Note that there are some explanatory texts on larger screens.

plurals
  1. POWhy PreferenceActivity throws UnsupportedEncodingException?
    primarykey
    data
    text
    <p>I'm trying to add settings to my application using PreferenceActivity (I'm targeting API level 8), I started with only one checkbox:</p> <pre><code>&lt;?xml version="1.0" encoding="utf-8"?&gt; &lt;PreferenceScreen xmlns:android="http://schemas.android.com/apk/res/android"&gt; &lt;CheckBoxPreference android:key="pref_fps" android:title="FPS" android:defaultValue="false" /&gt; &lt;/PreferenceScreen&gt; </code></pre> <p>My PreferenceActivity subclass only defines one "onCreate" method:</p> <pre><code>@Override public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); addPreferencesFromResource(R.xml.preferences); } </code></pre> <p>Everything seemed to be working fine at first, but I noticed that preferences were lost after an application restart. Looking at the logs, it seems the preferences can't be saved to disk. Every time I click on the checkbox in the PreferenceActivity, I'm getting this exception:</p> <pre><code>W/ApplicationContext( 9542): writeFileLocked: Got exception: W/ApplicationContext( 9542): java.io.UnsupportedEncodingException: utf-8 W/ApplicationContext( 9542): at com.android.internal.util.FastXmlSerializer.setOutput(FastXmlSerializer.java:297) W/ApplicationContext( 9542): at com.android.internal.util.XmlUtils.writeMapXml(XmlUtils.java:181) W/ApplicationContext( 9542): at android.app.ContextImpl$SharedPreferencesImpl.writeFileLocked(ContextImpl.java:2928) W/ApplicationContext( 9542): at android.app.ContextImpl$SharedPreferencesImpl.access$300(ContextImpl.java:2676) W/ApplicationContext( 9542): at android.app.ContextImpl$SharedPreferencesImpl$EditorImpl.commit(ContextImpl.java:2861) W/ApplicationContext( 9542): at android.preference.Preference.tryCommit(Preference.java:1198) W/ApplicationContext( 9542): at android.preference.Preference.persistBoolean(Preference.java:1403) W/ApplicationContext( 9542): at android.preference.CheckBoxPreference.setChecked(CheckBoxPreference.java:154) W/ApplicationContext( 9542): at android.preference.CheckBoxPreference.onClick(CheckBoxPreference.java:143) W/ApplicationContext( 9542): at android.preference.Preference.performClick(Preference.java:810) W/ApplicationContext( 9542): at android.preference.PreferenceScreen.onItemClick(PreferenceScreen.java:198) W/ApplicationContext( 9542): at android.widget.AdapterView.performItemClick(AdapterView.java:284) W/ApplicationContext( 9542): at android.widget.ListView.performItemClick(ListView.java:3382) W/ApplicationContext( 9542): at android.widget.AbsListView$PerformClick.run(AbsListView.java:1696) W/ApplicationContext( 9542): at android.os.Handler.handleCallback(Handler.java:587) W/ApplicationContext( 9542): at android.os.Handler.dispatchMessage(Handler.java:92) W/ApplicationContext( 9542): at android.os.Looper.loop(Looper.java:144) W/ApplicationContext( 9542): at android.app.ActivityThread.main(ActivityThread.java:4937) W/ApplicationContext( 9542): at java.lang.reflect.Method.invokeNative(Native Method) W/ApplicationContext( 9542): at java.lang.reflect.Method.invoke(Method.java:521) W/ApplicationContext( 9542): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:868) W/ApplicationContext( 9542): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:626) W/ApplicationContext( 9542): at dalvik.system.NativeStart.main(Native Method) W/ApplicationContext( 9542): Caused by: java.nio.charset.UnsupportedCharsetException: The unsupported charset name is "utf-8". W/ApplicationContext( 9542): at java.nio.charset.Charset.forName(Charset.java:544) W/ApplicationContext( 9542): at com.android.internal.util.FastXmlSerializer.setOutput(FastXmlSerializer.java:292) W/ApplicationContext( 9542): ... 22 more </code></pre> <p>Behavior is the same on the emulator and on a real device.</p> <p>What am I doing wrong?</p>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload