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 8646187
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 12, 20262026-06-12T12:44:22+00:00 2026-06-12T12:44:22+00:00

I have a preference activity which contains a checkbox and a list preference. The

  • 0

I have a preference activity which contains a checkbox and a list preference. The main activity of this application gets the current value of the list preference and uses it as the url to gain data from. My problem is that on a fresh install the default value is not being set, thus the value being null and the app instantly crashes before being able to get to the preference screen. Any fixes??

CODE:

public class Preferences extends PreferenceActivity implements OnSlideMenuItemClickListener {
private SlideMenu slidemenu;
private final static int News = 1;
private final static int Library = 2;
private final static int Photos = 3;
private final static int Videos = 4;
private final static int Maps = 5;
private final static int Prefs = 6;
private final static int About = 7;
GoogleAnalyticsTracker tracker;
@Override
protected void onCreate(Bundle savedInstanceState) {

    super.onCreate(savedInstanceState);
    addPreferencesFromResource(R.xml.preferences);
    setContentView(R.layout.show_settings_layout);
    tracker = GoogleAnalyticsTracker.getInstance();
    tracker.startNewSession("UA-35087731-1", 10, this);
    Typeface blockFonts = Typeface.createFromAsset(getAssets(),"FUTURAM.TTF");
    TextView lblTitle = (TextView) findViewById(R.id.actionbar); 
    lblTitle.setText("Preferences");
    lblTitle.setTypeface(blockFonts);


          ListPreference listPreference = (ListPreference) findPreference("news_feed");
            if(listPreference.getValue()==null) {

                    listPreference.setValueIndex(1);
                final CheckBoxPreference checkboxPref = (CheckBoxPreference) getPreferenceManager().findPreference("french");

                checkboxPref.setOnPreferenceChangeListener(new Preference.OnPreferenceChangeListener() {            
                    public boolean onPreferenceChange(Preference preference, Object newValue) {
                        if(newValue.toString().equals("true")) {
                            ListPreference newsPref = (ListPreference) findPreference("news_feed");

                            String[] values = getResources().getStringArray(R.array.newsfeedfr);
                                    newsPref.setEntryValues(values);
                                    newsPref.setDefaultValue(values[1]);

                        }
                        else {
                            ListPreference news2Pref = (ListPreference) findPreference("news_feed");                                
                            String[] values2 = getResources().getStringArray(R.array.newsfeed);                                     news2Pref.setEntryValues(values2);                                  news2Pref.setDefaultValue(values2[1]);

                        }      
                        return true;
                    }
            }); }
}
    }

 SharedPreferences sharedPrefs = 
                PreferenceManager.getDefaultSharedPreferences(getBaseContext());
     URL= sharedPrefs.getString("news_feed", "N/A");
        if(URL==null) {
            URL = "http://scout.org/rss/feed/all";
        }

And this is how I retrieve the value in the News Class


LOGCAT OUTPUT

10-08 00:52:06.569: E/WindowManager(305): Activity org.scouts.android.news.News has  leaked window com.android.internal.policy.impl.PhoneWindow$DecorView@44eb8558 that was originally added here
10-08 00:52:06.569: E/WindowManager(305): android.view.WindowLeaked: Activity org.scouts.android.news.News has leaked window com.android.internal.policy.impl.PhoneWindow$DecorView@44eb8558 that was originally added here
10-08 00:52:06.569: E/WindowManager(305):   at android.view.ViewRoot.<init>(ViewRoot.java:247)
10-08 00:52:06.569: E/WindowManager(305):   at android.view.WindowManagerImpl.addView(WindowManagerImpl.java:148)
10-08 00:52:06.569: E/WindowManager(305):   at android.view.WindowManagerImpl.addView(WindowManagerImpl.java:91)
10-08 00:52:06.569: E/WindowManager(305):   at android.view.Window$LocalWindowManager.addView(Window.java:424)
10-08 00:52:06.569: E/WindowManager(305):   at android.app.Dialog.show(Dialog.java:241)
10-08 00:52:06.569: E/WindowManager(305):   at org.scouts.android.news.News$MyAsyncgTask.onPreExecute(News.java:171)
10-08 00:52:06.569: E/WindowManager(305):   at android.os.AsyncTask.execute(AsyncTask.java:391)
10-08 00:52:06.569: E/WindowManager(305):   at org.scouts.android.news.News.onCreate(News.java:100)
10-08 00:52:06.569: E/WindowManager(305):   at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1047)
10-08 00:52:06.569: E/WindowManager(305):   at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2627)
10-08 00:52:06.569: E/WindowManager(305):   at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2679)
10-08 00:52:06.569: E/WindowManager(305):   at android.app.ActivityThread.access$2300(ActivityThread.java:125)
10-08 00:52:06.569: E/WindowManager(305):   at android.app.ActivityThread$H.handleMessage(ActivityThread.java:2033)
10-08 00:52:06.569: E/WindowManager(305):   at android.os.Handler.dispatchMessage(Handler.java:99)
10-08 00:52:06.569: E/WindowManager(305):   at android.os.Looper.loop(Looper.java:123)
10-08 00:52:06.569: E/WindowManager(305):   at android.app.ActivityThread.main(ActivityThread.java:4627)
10-08 00:52:06.569: E/WindowManager(305):   at java.lang.reflect.Method.invokeNative(Native Method)
10-08 00:52:06.569: E/WindowManager(305):   at java.lang.reflect.Method.invoke(Method.java:521)
10-08 00:52:06.569: E/WindowManager(305):   at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:868)
10-08 00:52:06.569: E/WindowManager(305):   at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:626)
10-08 00:52:06.569: E/WindowManager(305):   at dalvik.system.NativeStart.main(Native Method)
10-08 00:52:35.980: I/Process(305): Sending signal. PID: 305 SIG: 9
  • 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-12T12:44:24+00:00Added an answer on June 12, 2026 at 12:44 pm

    The problem was a little silly, but in the line

    URL= sharedPrefs.getString(“news_feed”, “N/A”);

    it return N/A for the value, when there is no user selected one, instead of null hence the fix being

    URL= sharePrefs.getString(“news_feed”, null);

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

Sidebar

Related Questions

I am using fragments to show images/pages.I have one Activity(Main) which contains all the
I have a TabActivity which starts when the application is launched. It contains 3
I have an app with 2 activities, the preference and the main activity, I
In my application i have a listView. each item of the list view contains
I have a user preference in my app, which gets used by different activities.
I have an activity that I'd like to load from a preference screen. I'm
I have a very simple activity just to show the preference fragment: public class
I would like to have a checkbox preference that takes the user to a
I have written an application that keeps erasing my shared preference. It was always
I have a OnPreferenceClickListener which should remove a specific Preference (with key preference_to_remove )

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.