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

  • Home
  • SEARCH
  • 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 6133297
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 23, 20262026-05-23T17:12:35+00:00 2026-05-23T17:12:35+00:00

I know this cannot be as hard I think it is. I am sure

  • 0

I know this cannot be as hard I think it is. I am sure I have everything that I can suppose to to implement my onClickListener. Am I missing something, why does this forceclose? I have provided the stack to take a look at. Any help would be great. This was suppose to be a simple activity to save user settings. If I comment out this code the activity displays the activity.

Preference customPref = (Preference) findPreference("customPref");

customPref.setOnPreferenceClickListener(new OnPreferenceClickListener() { //this line forcecloses every time i run the activity.
    @Override
    public boolean onPreferenceClick(Preference preference) {
        Toast.makeText(getBaseContext(),
                       "The custom preference has been clicked",
                       Toast.LENGTH_LONG)
             .show();
        SharedPreferences customSharedPreference = getSharedPreferences(
                "myCustomSharedPrefs", Activity.MODE_PRIVATE);
        SharedPreferences.Editor editor = customSharedPreference.edit();
        editor.putString("myCustomPref", "The preference has been clicked");
        editor.commit();
        return true;
    }
});

Logs:

07-10 16:36:47.137: WARN/System.err(1042): java.lang.NullPointerException
07-10 16:36:47.147: WARN/System.err(1042):     at com.nyneaxis.android.mpg.Preferences.onCreate(Preferences.java:22)
07-10 16:36:47.147: WARN/System.err(1042):     at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1047)
07-10 16:36:47.157: WARN/System.err(1042):     at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2459)
07-10 16:36:47.157: WARN/System.err(1042):     at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2512)
07-10 16:36:47.157: WARN/System.err(1042):     at android.app.ActivityThread.access$2200(ActivityThread.java:119)
07-10 16:36:47.157: WARN/System.err(1042):     at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1863)
07-10 16:36:47.167: WARN/System.err(1042):     at android.os.Handler.dispatchMessage(Handler.java:99)
07-10 16:36:47.167: WARN/System.err(1042):     at android.os.Looper.loop(Looper.java:123)
07-10 16:36:47.167: WARN/System.err(1042):     at android.app.ActivityThread.main(ActivityThread.java:4363)
07-10 16:36:47.167: WARN/System.err(1042):     at java.lang.reflect.Method.invokeNative(Native Method)
07-10 16:36:47.177: WARN/System.err(1042):     at java.lang.reflect.Method.invoke(Method.java:521)
07-10 16:36:47.177: WARN/System.err(1042):     at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:860)
07-10 16:36:47.177: WARN/System.err(1042):     at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:618)
07-10 16:36:47.177: WARN/System.err(1042):     at dalvik.system.NativeStart.main(Native Method)
  • 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-23T17:12:36+00:00Added an answer on May 23, 2026 at 5:12 pm

    It looks like your customPref variable is null. Make sure you have preference with key customPref in your preference xml (if you use one) or maybe you’ve misspelled the key there.

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

Sidebar

Related Questions

I know that I've seen this site before, but cannot remember it for the
I think i already know the answer to this, but i cannot find anything
I know that this question has been asked loads of times, but I have
I know this may be basic but I cannot seem to add a member
I know this is probably really obvious, but I cannot figure out why I
I cannot find this in the documentation anywhere. Does anyone know if this is
I know we cannot do this at class level but at method level we
I know this isn't strictly a programming question but y'all must have experienced this.
I have an executable that is started by a windows service, this program will
I'm having a hard time trying to do this. I have this code here:

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.