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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 10, 20262026-06-10T03:05:48+00:00 2026-06-10T03:05:48+00:00

I am new in developing in Java. I am making an app which uses

  • 0

I am new in developing in Java. I am making an app which uses SharedPreferences. The the specific tutorial I used is this:

http://blog.donnfelker.com/2011/02/17/android-a-simple-eula-for-your-android-apps/

I have modified the code a bit, but it is giving me an error:

public class SimpleEula extends Application {
    private String EULA_PREFIX = "eula";
    public Activity mActivity;

    public SimpleEula(Activity context) {
        mActivity = context;
    }

    public void showEula() {
        SharedPreferences sh_showEula;
        final String eulaKey = EULA_PREFIX;
        final SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(mActivity);
        ...

I log my code after every line, and my app crashes at:

    final SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(mActivity);

Even if I change the line to:

    final SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(this);

I still get a crash. I don’t know what the problem is. Could someone help me?

Thanks in advance

EDIT:

These are the errors in LogCat:

08-21 20:44:58.905: E/AndroidRuntime(610): FATAL EXCEPTION: main
08-21 20:44:58.905: E/AndroidRuntime(610): java.lang.RuntimeException: Unable to start activity ComponentInfo{com.test.test/com.test.test.MainActivity}: java.lang.NullPointerException
08-21 20:44:58.905: E/AndroidRuntime(610):  at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:1956)
08-21 20:44:58.905: E/AndroidRuntime(610):  at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:1981)
08-21 20:44:58.905: E/AndroidRuntime(610):  at android.app.ActivityThread.access$600(ActivityThread.java:123)
08-21 20:44:58.905: E/AndroidRuntime(610):  at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1147)
08-21 20:44:58.905: E/AndroidRuntime(610):  at android.os.Handler.dispatchMessage(Handler.java:99)
08-21 20:44:58.905: E/AndroidRuntime(610):  at android.os.Looper.loop(Looper.java:137)
08-21 20:44:58.905: E/AndroidRuntime(610):  at android.app.ActivityThread.main(ActivityThread.java:4424)
08-21 20:44:58.905: E/AndroidRuntime(610):  at java.lang.reflect.Method.invokeNative(Native Method)
08-21 20:44:58.905: E/AndroidRuntime(610):  at java.lang.reflect.Method.invoke(Method.java:511)
08-21 20:44:58.905: E/AndroidRuntime(610):  at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:784)
08-21 20:44:58.905: E/AndroidRuntime(610):  at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:551)
08-21 20:44:58.905: E/AndroidRuntime(610):  at dalvik.system.NativeStart.main(Native Method)
08-21 20:44:58.905: E/AndroidRuntime(610): Caused by: java.lang.NullPointerException
08-21 20:44:58.905: E/AndroidRuntime(610):  at android.preference.PreferenceManager.getDefaultSharedPreferencesName(PreferenceManager.java:371)
08-21 20:44:58.905: E/AndroidRuntime(610):  at android.preference.PreferenceManager.getDefaultSharedPreferences(PreferenceManager.java:366)
08-21 20:44:58.905: E/AndroidRuntime(610):  at com.test.test.SimpleEula.show(SimpleEula.java:23)
08-21 20:44:58.905: E/AndroidRuntime(610):  at com.test.test.MainActivity.onCreate(MainActivity.java:26)
08-21 20:44:58.905: E/AndroidRuntime(610):  at android.app.Activity.performCreate(Activity.java:4465)
08-21 20:44:58.905: E/AndroidRuntime(610):  at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1049)
08-21 20:44:58.905: E/AndroidRuntime(610):  at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:1920)
08-21 20:44:58.905: E/AndroidRuntime(610):  ... 11 more
  • 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-10T03:05:50+00:00Added an answer on June 10, 2026 at 3:05 am

    The NullPointerExepter is caused by extending the Activity or Application class. This code works:

    public class SimpleEula {
    
        private String EULA_PREFIX = "eula";
        private Activity mActivity;
    
        public SimpleEula(Activity context) {
            mActivity = context;
        }
    
        public void show() {
            final String eulaKey = EULA_PREFIX;
            final SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(mActivity);
                ...
    

    Now it works. Thank you all for your help

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

Sidebar

Related Questions

Developing a brand new schema/app which uses hibernate to create tables from pojo's. My
I'm new in Java. I'm developing program for Android similar to app for iOS.
I am developing a new Java Desktop app. Something like a media player. I
I'm developing a java web app on my local PC that uses a file
I'm very new to Java but I've been developing a habit to use final
I'm developing new web app with Struts2 framework, eclipse, and I've mapped the db
I'm new in developing iOS app. So I've recently faced a problem with localization
Even if I'm not new to Java, I've only used it in school/university environment
This problem is solved. I'm am developing a Java Swing based projected, and the
I'm quite new to developing Android apps. Basically I'm making a webview template to

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.