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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 19, 20262026-05-19T01:36:10+00:00 2026-05-19T01:36:10+00:00

I have been working on an application and I added a options menu. Prior

  • 0

I have been working on an application and I added a options menu. Prior to adding the menu everything ran fine, after adding however it will not run, the process just stops.
I tried removing the menu and that did not work, it still stops. In logcat it says that there is a null pointer exception, but I cannot figure out at all why this is happening.

my numbers_menu xml file:

<?xml version="1.0" encoding="utf-8"?>
<menu xmlns:android="http://schemas.android.com/apk/res/android">

<item android:id="@+id/quit" 
   android:title="@string/quit_str" ></item>

<item android:id="@+id/instructions" 
      android:title="@string/instructions_str"></item>

</menu>

methods:

   @Override
    public boolean onCreateOptionsMenu(Menu menu) {
     MenuInflater inflater = getMenuInflater();
     inflater.inflate(R.menu.numbers_menu, menu);
  return true;
    }

    @Override
    public boolean onOptionsItemSelected(MenuItem item) {
        switch (item.getItemId()) {
        case R.id.quit:
            quit();
            return true;
        case R.id.instructions:
            return true;
        default:
            return super.onOptionsItemSelected(item);
        }
    }

Here is the code leading up the the null pointer exception:

@Override
public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);

    setContentView(R.layout.main);

    play_game();

    }

public void play_game() {

     //get some numbers
     rolled1 = roll();
     Log.d(TAG, "rolled1 is up");
     rolled2 = roll();
     Log.d(TAG, "rolled2 is up");

        switch(rolled1) {
     case 1:
      rolled_id_1 = 2131034114;
      break;
     case 2:
      rolled_id_1 = 2131034115;
      break;
     case 3:
      rolled_id_1 = 2131034116;
      break;
     case 4:
      rolled_id_1 = 2131034117;
      break;
     case 5:
      rolled_id_1 = 2131034119;
      break;
     case 6:
      rolled_id_1 = 2131034120;
      break;
     }

        Log.d(TAG, "rolled_id_1 is up with the value " + Integer.toString(rolled_id_1));

     switch(rolled2) {
     case 1:
      rolled_id_2 = 2131034114;
      break;
     case 2:
      rolled_id_2 = 2131034115;
      break;
     case 3:
      rolled_id_2 = 2131034116;
      break;
     case 4:
      rolled_id_2 = 2131034117;
      break;
     case 5:
      rolled_id_2 = 2131034119;
      break;
     case 6:
      rolled_id_2 = 2131034120;
      break;
     }

     Log.d(TAG, "rolled_id_2 is up with the value " + Integer.toString(rolled_id_2));

     switch(rolled1 + rolled2) { 
     case 1:
      rolled_sum = 2131034114;
      break;
     case 2:
      rolled_sum = 2131034115;
      break;
     case 3:
      rolled_sum = 2131034116;
      break;
     case 4:
      rolled_sum = 2131034117;
      break;
     case 5:
      rolled_sum = 2131034119;
      break;
     case 6:
      rolled_sum = 2131034120;
      break;
     case 7:
      rolled_sum = 2131034121;  
      break;
     case 8:
      rolled_sum = 2131034122;   
      break;
     case 9:
      rolled_sum = 2131034124; 
      break;
     case 10:
      rolled_sum = 2131034125;  
      break;
     case 11:
      rolled_sum = 2131034126;  
      break;
     case 12:
      rolled_sum = 2131034127;
      break;
     }

     Log.d(TAG, "rolled_id_sum is up with the value " + Integer.toString(rolled_sum));

     if(lose(rolled_id_1, rolled_id_2, rolled_sum)) {
      dieShow(rolled1, rolled2);
      setContentView(R.layout.main);
      play_game();
     }
     else {
          disable_flag = 0;
          needDisable(rolled_id_1, rolled_id_2);
             dieShow(rolled1, rolled2);
         }



        }

public boolean lose(int rolled_id_1, int rolled_id_2, int rolled_sum) {
     //check loss
     Button button_check_loss_1 = (Button)findViewById(rolled_id_1);
     Log.d(TAG, "getting past first button assignment");
     Button button_check_loss_2 = (Button)findViewById(rolled_id_2);
     Log.d(TAG, "getting past second button assignment");
     Button button_check_loss_3 = (Button)findViewById(rolled_sum);
     Log.d(TAG, "getting past third button assignment");

     if((!button_check_loss_1.isClickable() || !button_check_loss_2.isClickable()) && !button_check_loss_3.isClickable()) {
      Toast loseText = Toast.makeText(this, "you lose1", Toast.LENGTH_LONG);
      loseText.show();
      return true;
     }

     if(!button_check_loss_1.isClickable() && !button_check_loss_2.isClickable() && !button_check_loss_3.isClickable()) {
      Toast loseText = Toast.makeText(this, "you lose2", Toast.LENGTH_LONG);
      loseText.show();
      return true;

     }

     if(rolled_id_1 == rolled_id_2) {
      if ((!button_check_loss_1.isClickable() || !button_check_loss_2.isClickable()) && !button_check_loss_3.isClickable()) {
          Toast loseText = Toast.makeText(this, "you lose3", Toast.LENGTH_LONG);
          loseText.show();
          return true;
      }
     }

     return false;

    }

The error occurs at:

if((!button_check_loss_1.isClickable() || !button_check_loss_2.isClickable()) && !button_check_loss_3.isClickable())
  • 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-19T01:36:11+00:00Added an answer on May 19, 2026 at 1:36 am
    case 1:
        rolled_id_1 = 2131034114;
        break;
    

    Let me guess…2131034114 is the int Id of a button that you have taken from /gen/…/R.java – am I correct?

    If so this is REALLY NOT a good way of doing things. The contents of the generated R.java file are not guaranteed to be constant – by adding the options menu, the chances are the int Ids of all (or some) of the Buttons have changed.

    The reason you’re getting a NullPointerException is likely to be that this code…

    Button button_check_loss_1 = (Button)findViewById(rolled_id_1);
    Log.d(TAG, "getting past first button assignment");
    Button button_check_loss_2 = (Button)findViewById(rolled_id_2);
    Log.d(TAG, "getting past second button assignment");
    Button button_check_loss_3 = (Button)findViewById(rolled_sum);
    Log.d(TAG, "getting past third button assignment");
    

    …probably can’t find one (or all) of those Button Ids. You need to use R.id.button1 (for example) when assigning to rolled_id_1.

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

Sidebar

Related Questions

No related questions found

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.