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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 11, 20262026-06-11T15:57:26+00:00 2026-06-11T15:57:26+00:00

What am doing wrong in the following code? SharedPreferences mPreferences; /** Called when the

  • 0

What am doing wrong in the following code?

SharedPreferences mPreferences;

    /** Called when the activity is first created. */
    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);

    setContentView(R.layout.splash);
        new Handler().postDelayed(new Runnable() {

            public void run() {
                init();
                callFunc();
            }

        }, SPLASH_DISPLAY_LENGHT);
        // }
    }

    boolean firstTime() {
        boolean firstTime = mPreferences.getBoolean("firstTime", true);
        if (firstTime) {
            SharedPreferences.Editor editor = mPreferences.edit();
            editor.putBoolean("firstTime", false);
            editor.commit();
            return true;
        } else {
            return false;
        }
    }

    void callFunc(){
        if(firstTime()){
            callDetailedScreen();           
        }
        else{
            CallMainScreen();   
        }
    }

logcat

09-21 03:28:58.948: E/AndroidRuntime(314): FATAL EXCEPTION: main
09-21 03:28:58.948: E/AndroidRuntime(314): java.lang.NullPointerException
09-21 03:28:58.948: E/AndroidRuntime(314):  at com.x.y.Main.firstTime(Main.java:38)
09-21 03:28:58.948: E/AndroidRuntime(314):  at com.x.y.callFunc(Main.java:50)
09-21 03:28:58.948: E/AndroidRuntime(314):  at com.x.y.Main$2.run(Main.java:30)
09-21 03:28:58.948: E/AndroidRuntime(314):  at android.os.Handler.handleCallback(Handler.java:587)
09-21 03:28:58.948: E/AndroidRuntime(314):  at android.os.Handler.dispatchMessage(Handler.java:92)
09-21 03:28:58.948: E/AndroidRuntime(314):  at android.os.Looper.loop(Looper.java:123)
09-21 03:28:58.948: E/AndroidRuntime(314):  at android.app.ActivityThread.main(ActivityThread.java:4627)
09-21 03:28:58.948: E/AndroidRuntime(314):  at java.lang.reflect.Method.invokeNative(Native Method)
09-21 03:28:58.948: E/AndroidRuntime(314):  at java.lang.reflect.Method.invoke(Method.java:521)
09-21 03:28:58.948: E/AndroidRuntime(314):  at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:868)
09-21 03:28:58.948: E/AndroidRuntime(314):  at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:626)
09-21 03:28:58.948: E/AndroidRuntime(314):  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-06-11T15:57:28+00:00Added an answer on June 11, 2026 at 3:57 pm

    Based on the code you posted and your logcat, you are not instantiating your SharedPreferences.

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

Sidebar

Related Questions

I'm sure I'm doing something stupid here, but the following code: ... public void
What am I doing wrong in the following code? public string ReadFromFile(string text) {
I can't figure out what I'm doing wrong here. I have the following code:
Is there anything i am doing wrong in the following code. Ob_start should buffer
I seem to be doing something wrong in the following code: http://jsfiddle.net/yunowork/qKj6b/1/ When you
Can someone please point out what I am doing wrong in the following code?
What im doing wrong this time? The following code always returns 4 bytes only,
I can't seem to figure out what i'm doing wrong with the following code:
So what am I doing wrong? When I run the following code, the database
The following code to parse JSON is not working. What am I doing wrong?

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.