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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 24, 20262026-05-24T16:14:04+00:00 2026-05-24T16:14:04+00:00

I am struggling why I’m getting this exception when registering this listener, and I

  • 0

I am struggling why I’m getting this exception when registering this listener, and I can’t find it out.

The problem seems to be when prefs.registerOnSharedPreferenceChangeListener(listener); but I can’t find the solution!

The code is the following:

public class MtprojectActivity extends Activity {

public void onCreate(Bundle savedInstanceState) {
[...]
OnSharedPreferenceChangeListener listener = new SharedPreferences.OnSharedPreferenceChangeListener() {
            public void onSharedPreferenceChanged(SharedPreferences prefs,
                    String key) {
                if (key.equals("CALLS_FREQUENCY_PREF")) {
                    newCallsFrequencyValue = Integer.parseInt(prefs.getString(Preferences.CALLS_FREQUENCY_PREF, "0"));

                } else if (key.equals("SMS_FREQUENCY_PREF")) {
                    newSmsFrequencyValue = Integer.parseInt(prefs.getString(Preferences.SMS_FREQUENCY_PREF, "0"));

                } else if (key.equals("LOC_FREQUENCY_PREF")) {
                    newLocationFrequencyValue = Integer.parseInt(prefs.getString(Preferences.LOCATION_FREQUENCY_PREF, "0"));
                }
            }
        };

        prefs.registerOnSharedPreferenceChangeListener(listener);

And this is the exception trace:

08-10 15:31:39.537: ERROR/AndroidRuntime(547): FATAL EXCEPTION: main
08-10 15:31:39.537: ERROR/AndroidRuntime(547): java.lang.RuntimeException: Unable to start activity ComponentInfo{app.mtproject/app.mtproject.MtprojectActivity}: java.lang.NullPointerException
08-10 15:31:39.537: ERROR/AndroidRuntime(547):     at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:1647)
08-10 15:31:39.537: ERROR/AndroidRuntime(547):     at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:1663)
08-10 15:31:39.537: ERROR/AndroidRuntime(547):     at android.app.ActivityThread.access$1500(ActivityThread.java:117)
08-10 15:31:39.537: ERROR/AndroidRuntime(547):     at android.app.ActivityThread$H.handleMessage(ActivityThread.java:931)
08-10 15:31:39.537: ERROR/AndroidRuntime(547):     at android.os.Handler.dispatchMessage(Handler.java:99)
08-10 15:31:39.537: ERROR/AndroidRuntime(547):     at android.os.Looper.loop(Looper.java:130)
08-10 15:31:39.537: ERROR/AndroidRuntime(547):     at android.app.ActivityThread.main(ActivityThread.java:3683)
08-10 15:31:39.537: ERROR/AndroidRuntime(547):     at java.lang.reflect.Method.invokeNative(Native Method)
08-10 15:31:39.537: ERROR/AndroidRuntime(547):     at java.lang.reflect.Method.invoke(Method.java:507)
08-10 15:31:39.537: ERROR/AndroidRuntime(547):     at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:839)
08-10 15:31:39.537: ERROR/AndroidRuntime(547):     at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:597)
08-10 15:31:39.537: ERROR/AndroidRuntime(547):     at dalvik.system.NativeStart.main(Native Method)
08-10 15:31:39.537: ERROR/AndroidRuntime(547): Caused by: java.lang.NullPointerException
08-10 15:31:39.537: ERROR/AndroidRuntime(547):     at app.mtproject.MtprojectActivity.onCreate(MtprojectActivity.java:88)
08-10 15:31:39.537: ERROR/AndroidRuntime(547):     at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1047)
08-10 15:31:39.537: ERROR/AndroidRuntime(547):     at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:1611)
08-10 15:31:39.537: ERROR/AndroidRuntime(547):     ... 11 more

Thanks a lot in advance!

  • 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-05-24T16:14:05+00:00Added an answer on May 24, 2026 at 4:14 pm

    Ok, just make sure the variable prefs has been properly called before containing the SharedPreferences retrieved from the activity =)

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

Sidebar

Related Questions

Im struggling to find an answer for this one. I've found out how to
Been struggling with this simple selector problem a couple of hours now and must
I'm struggling to find the right terminology here, but if you have jQuery object...
A coworker has been struggling with this problem. The desired result is an installable
Struggling with this tournament fixtures algorithm. The code is working perfectly but I need
Struggling with this problem for an hour now and searched both stackoverflow and google
Struggling with command line again, I have figure out that I can store the
Really struggling to work this out... I have a text file with data like
In struggling with a solution to this problem I've run into another, related issue:
Really struggling to figure this out. Just trying to take in data from php

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.