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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 24, 20262026-05-24T19:47:30+00:00 2026-05-24T19:47:30+00:00

I am getting a null pointer exception every time the user selects logout (R.Id.logout)

  • 0

I am getting a null pointer exception every time the user selects “logout” (R.Id.logout) from the option menu. I can’t figure out what I’m not initialising.

@Override
        public boolean onOptionsItemSelected(MenuItem item)
        {
            switch (item.getItemId())
            {
                case R.id.settings:             
                    return false;
                case R.id.about:
                    this.startActivity(new Intent(this, About.class));
                    return true;
                case R.id.logout:
                    AlertDialog.Builder alertbox = new AlertDialog.Builder(this);
                    alertbox.setTitle("Logout");
                    alertbox.setMessage("Logging out will remove your credentials from this phone. \nDo you want to logout?");
                    alertbox.setPositiveButton("Yes", new DialogInterface.OnClickListener() 
                    {                   
                        public void onClick(DialogInterface dialog, int id) 
                        {
                            Editor e = loginPref.edit();
                            e.clear();

                            Homepage.this.startActivity(new Intent(getApplicationContext(), Login.class));
                            Homepage.this.finish();             
                        }
                    });
                    alertbox.setNegativeButton("No", new DialogInterface.OnClickListener()
                    {                   
                        public void onClick(DialogInterface dialog, int id) 
                        {
                            dialog.cancel();                    
                        }
                    });
                    AlertDialog alert = alertbox.show();
                    return true;
            }
            return false;
        }

logCat

08-16 10:09:49.705: ERROR/AndroidRuntime(1531): FATAL EXCEPTION: main
08-16 10:09:49.705: ERROR/AndroidRuntime(1531): java.lang.NullPointerException
08-16 10:09:49.705: ERROR/AndroidRuntime(1531):     at org.*****.android.Homepage$1.onClick(Homepage.java:79)
08-16 10:09:49.705: ERROR/AndroidRuntime(1531):     at com.android.internal.app.AlertController$ButtonHandler.handleMessage(AlertController.java:158)
08-16 10:09:49.705: ERROR/AndroidRuntime(1531):     at android.os.Handler.dispatchMessage(Handler.java:99)
08-16 10:09:49.705: ERROR/AndroidRuntime(1531):     at android.os.Looper.loop(Looper.java:123)
08-16 10:09:49.705: ERROR/AndroidRuntime(1531):     at android.app.ActivityThread.main(ActivityThread.java:4627)
08-16 10:09:49.705: ERROR/AndroidRuntime(1531):     at java.lang.reflect.Method.invokeNative(Native Method)
08-16 10:09:49.705: ERROR/AndroidRuntime(1531):     at java.lang.reflect.Method.invoke(Method.java:521)
08-16 10:09:49.705: ERROR/AndroidRuntime(1531):     at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:868)
08-16 10:09:49.705: ERROR/AndroidRuntime(1531):     at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:626)
08-16 10:09:49.705: ERROR/AndroidRuntime(1531):     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-24T19:47:33+00:00Added an answer on May 24, 2026 at 7:47 pm

    It’s quite simple. Something on line 79 in Homepage.java is null. Please check what line this is and post it or post the complete code, with package name and everything so that we actually can help because now we can only guess what’s actually null.

    My first guess would be loginPref at:

      Editor e = loginPref.edit();
    

    Have you initialized loginPref?

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

Sidebar

Related Questions

I am getting null pointer exception when I am trying to get lat/long from
I'm getting a null pointer exception even if i already started the thread. Is
Iam getting a null pointer exception while sending some string text as an sms
I am getting same null pointer exception while running integration test in eclipse .while
I am getting Null Pointer Exception for ImageView imag = (ImageView) findViewById(R.id.image). I have
I am getting null pointer exception, due to failed to recognize layout parameter in
I try in following way but I am getting Null Pointer Exception at iv.setImageBitmap(bm).
I am getting a null pointer exception when trying to set up datasource in
I'm writing a Linux module and getting: Unable to handle kernel NULL pointer dereference
I keep getting a null exception at the ; below. The ApiUsername & ApiPassword

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.