Application crashes when user tries to open a PreferenceActivity
<p>I only have a Windows where you push menu -> preferences and launch an <strong>Intent</strong></p>

<pre><code>@Override
public boolean onMenuItemSelected(int featureId, MenuItem item) {
    switch (item.getItemId()) {
        case R.id.menu_settings:
            startActivity(new Intent(this, com.example.app.PreferenciasGenerales.class));
            return true;
        default:
            return false;
    }
}
</code></pre>

<p>Automatically it says that the application has to be closed.</p>

<pre><code>Uncaught handler: thread main exiting due to uncaught exception
java.lang.RuntimeException: Unable to start activity ComponentInfo{com.example.app/com.example.app.PreferenciasGenerales}:
java.lang.ClassCastException: java.lang.Integer
    at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2496)
    at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2512)
    at android.app.ActivityThread.access$2200(ActivityThread.java:119)
    at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1863)
    at android.os.Handler.dispatchMessage(Handler.java:99)
    at android.os.Looper.loop(Looper.java:123)
    at android.app.ActivityThread.main(ActivityThread.java:4363)
    at java.lang.reflect.Method.invokeNative(Native Method)
    at java.lang.reflect.Method.invoke(Method.java:521)
    at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:860)
    at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:618)
    at dalvik.system.NativeStart.main(Native Method)
Caused by: java.lang.ClassCastException: java.lang.Integer
    at android.app.ApplicationContext$SharedPreferencesImpl.getString(ApplicationContext.java:2572)
    at android.preference.Preference.getPersistedString(Preference.java:1250)
    at android.preference.ListPreference.onSetInitialValue(ListPreference.java:232)
    at android.preference.Preference.dispatchSetInitialValue(Preference.java:1173)
    at android.preference.Preference.onAttachedToHierarchy(Preference.java:985)
    at android.preference.PreferenceGroup.addPreference(PreferenceGroup.java:156)
    at android.preference.PreferenceGroup.addItemFromInflater(PreferenceGroup.java:97)
    at android.preference.PreferenceGroup.addItemFromInflater(PreferenceGroup.java:38)
    at android.preference.GenericInflater.rInflate(GenericInflater.java:488)
    at android.preference.GenericInflater.rInflate(GenericInflater.java:493)
    at android.preference.GenericInflater.inflate(GenericInflater.java:326)
    at android.preference.GenericInflater.inflate(GenericInflater.java:263)
    at android.preference.PreferenceManager.inflateFromResource(PreferenceManager.java:254)
    at android.preference.PreferenceActivity.addPreferencesFromResource(PreferenceActivity.java:253)
 -&gt; at com.example.app.PreferenciasGenerales.onCreate(PreferenciasGenerales.java:34)
    at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1047)
    at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2459)
    ... 11 more
</code></pre>

<p>The PreferenceActivity that I want to launch is this:</p>

<pre><code>public class PreferenciasGenerales extends PreferenceActivity {
    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
    /*-&gt;*/addPreferencesFromResource(R.xml.preferencias_general);/*&lt;- Here is the exception at StackTrace */
    }

    @Override
    protected void onStop() {
        final ProgressDialog waitDialog =
            ProgressDialog.show( this, "Wait", "i'm testing that those things you write are correct...", true);
        waitDialog.setCancelable(false);
        /* Cannot have integers array on ListPreference
         * http://code.google.com/p/android/issues/detail?id=2096 */
        String old_debug_level = PreferenceManager.getDefaultSharedPreferences(this).getString("debug_level", "3");
        PreferenceManager.getDefaultSharedPreferences(this).edit()
        .remove("debug_level")
        .putInt("debug_level", Integer.parseInt(old_debug_level))
        .commit();
    old_debug_level = null;

    String api_server = PreferenceManager.getDefaultSharedPreferences(PreferenciasGenerales.this).getString("api_server", "");
    String account_id = PreferenceManager.getDefaultSharedPreferences(PreferenciasGenerales.this).getString("account_id", "");
    String account_pass = PreferenceManager.getDefaultSharedPreferences(PreferenciasGenerales.this).getString("account_pass", "");
    String account_key = PreferenceManager.getDefaultSharedPreferences(PreferenciasGenerales.this).getString("account_key", "");
    boolean debug_enabled= PreferenceManager.getDefaultSharedPreferences(PreferenciasGenerales.this).getBoolean("debug_enabled", false);
    int debug_level = PreferenceManager.getDefaultSharedPreferences(PreferenciasGenerales.this).getInt("debug_level", 3);

    try {
                 // Connect to API to test credentials...
</code></pre>

<p>More things that you'll need that are related to PreferenceActivity... I've removed all strings.xml values because they are too many and are in Spanish. All strings like title, hint, dialogTitle exists and are correct. They work on other Activities</p>

<p>/res/xml/preferencias_general.xml</p>

<pre><code>&lt;PreferenceScreen xmlns:android="http://schemas.android.com/apk/res/android" &gt;
    &lt;PreferenceCategory&gt;
        &lt;EditTextPreference android:key="api_server"/&gt;
    &lt;/PreferenceCategory&gt;
    &lt;PreferenceCategory android:title="@string/preferencias_cuenta_categoria_title"&gt;
        &lt;EditTextPreference android:key="account_id"  /&gt;
        &lt;EditTextPreference android:key="account_pass" /&gt;
        &lt;EditTextPreference android:key="account_key"  /&gt;
    &lt;/PreferenceCategory&gt;
        &lt;PreferenceCategory android:key="debug_enabled" /&gt;
        &lt;ListPreference android:key="debug_level" android:entryValues="@array/debug_level_entryValues" android:entries="@array/debug_level_entries" /&gt;
&lt;/PreferenceCategory&gt;
</code></pre>

<p></p>

<p>/res/values/preferencias_general.xml</p>

<pre><code>&lt;?xml version="1.0" encoding="utf-8"?&gt;
&lt;resources&gt;
    &lt;string-array name="debug_level_entries"&gt;
        &lt;item&gt;VERBOSE&lt;/item&gt;
        &lt;item&gt;DEBUG&lt;/item&gt;
        &lt;item&gt;INFO&lt;/item&gt;
        &lt;item&gt;WARN&lt;/item&gt;
        &lt;item&gt;ERROR&lt;/item&gt;
    &lt;/string-array&gt;
    &lt;string-array name="debug_level_entryValues"&gt;
        &lt;item&gt;1&lt;/item&gt;
        &lt;item&gt;2&lt;/item&gt;
        &lt;item&gt;3&lt;/item&gt;
        &lt;item&gt;4&lt;/item&gt;
        &lt;item&gt;5&lt;/item&gt;
   &lt;/string-array&gt;
</code></pre>

<p></p>

<p>Every Suggestion is welcome... and thanks for reading.</p>

<p>--</p>

<p><strong>UPDATE 1</strong>
On answer to @CommonsWere I wiped data out, and it shows it incomplete:</p>

<p><img src="http://i.stack.imgur.com/RllN5.png" alt="ListPreference when app settings are wiped out"></p>

<p>Before that, I try to exit and a new Exception raises up:</p>

<pre><code>java.lang.RuntimeException: Unable to stop activity {com.merinosa.kimera/com.merinosa.kimera.PreferenciasGenerales}:
java.lang.IllegalStateException: Target host must not be null, or set in parameters.
    at android.app.ActivityThread.performDestroyActivity(ActivityThread.java:3421)
    at android.app.ActivityThread.handleDestroyActivity(ActivityThread.java:3487)
    at android.app.ActivityThread.access$2800(ActivityThread.java:119)
    at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1896)
    at android.os.Handler.dispatchMessage(Handler.java:99)
    at android.os.Looper.loop(Looper.java:123)
    at android.app.ActivityThread.main(ActivityThread.java:4363)
    at java.lang.reflect.Method.invokeNative(Native Method)
    at java.lang.reflect.Method.invoke(Method.java:521)
    at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:860)
    at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:618)
    at dalvik.system.NativeStart.main(Native Method)
Caused by: java.lang.IllegalStateException: Target host must not be null, or set in parameters.
    at org.apache.http.impl.client.DefaultRequestDirector.determineRoute(DefaultRequestDirector.java:561)
    at org.apache.http.impl.client.DefaultRequestDirector.execute(DefaultRequestDirector.java:292)
    at org.apache.http.impl.client.AbstractHttpClient.execute(AbstractHttpClient.java:555)
    at org.apache.http.impl.client.AbstractHttpClient.execute(AbstractHttpClient.java:487)
    at org.apache.http.impl.client.AbstractHttpClient.execute(AbstractHttpClient.java:465)
    at com.example.app.PreferenciasGenerales.onStop(PreferenciasGenerales.java:78)
    at android.app.Instrumentation.callActivityOnStop(Instrumentation.java:1169)
    at android.app.Activity.performStop(Activity.java:3797)
    at android.app.ActivityThread.performDestroyActivity(ActivityThread.java:3416)
    ... 11 more
</code></pre>

<p>Where should I test if configurations are correct or not then?
If I run app again it goes to first error  again.</p>

<p>--</p>

<p><strong>UPDATE 2</strong></p>

<p>My new error has nothing to do with my original question so it can be set as answered.
The reason that the error reappears it's because I modify settings as CommonsWare says on the accepted answer.
When I exit from setting it executes onStop() and modify SharedPreferences to integer making it "uncasteable".</p>

<p>New errors has to be properly investigated and asked again if needed.</p>
