Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8835381
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 14, 20262026-06-14T09:14:54+00:00 2026-06-14T09:14:54+00:00

I only have a Window where you push menu -> preferences and launch an

  • 0

I only have a Window where you push menu -> preferences and launch an Intent

@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;
    }
}

Automatically it says that the application has to be closed.

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)
-> 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

The PreferenceActivity that I want to launch is this:

public class PreferenciasGenerales extends PreferenceActivity {
    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
    /*->*/addPreferencesFromResource(R.xml.preferencias_general);/*<- 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...

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

/res/xml/preferencias_general.xml

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

/res/values/preferencias_general.xml

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

—

UPDATE 1
On answer to @CommonsWere I wiped data out, and it shows it incomplete:

ListPreference when app settings are wiped out

Before that, I try to exit and a new Exception raises up:

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

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

—

UPDATE 2

My new error has nothing to do with my original question so it can be set as answered.
The reason that the error reappears is 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”.

New errors has to be properly investigated and asked again if needed.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-14T09:14:55+00:00Added an answer on June 14, 2026 at 9:14 am

    This app, on whatever device or emulator you are using for testing, already has saved SharedPreferences, where a saved value is an Integer, and you are now trying to load it into a Preference that expects a String. Try clearing the app’s data via Settings, or uninstalling and reinstalling the app, to clear up this problem.

    Also, please note that in your current preference XML, debug_level will be saved as a String, but you are attempting to retrieve it via getInt().

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

i have windows media player in my application.i want to allow only the supported
Assume i have a custom Windows application written in C#. This application has only
I have built an app that works only when not run as a Windows
I have a Java applet that is meant to run only on Windows. (It
Suppose I have a GUI-only application that runs on Windows and I'd like to
I have written a C# Windows Forms application, not a service (it is only
I have 2 instance in windows azure. I am finding that only one instance
You may have heard of PawSense , a Windows-only utility that prevents keystrokes from
Note: This problem occurs only on Mac, on Windows works fine. I have a
I only have one actual device to test on, a Nexus One but I've

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.