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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 16, 20262026-06-16T06:20:51+00:00 2026-06-16T06:20:51+00:00

I am currently working on an android project and I am having a bit

  • 0

I am currently working on an android project and I am having a bit of a strange issue. Its probably something really simple I’m missing but can’t see what I’ve done wrong.

I’ve added a new menu item to my XML file and then I am trying to reference the new menu item to either show it or hide it. The menu item is being shown on the screen when I run the app so I know I have the XML correct and have the correct file but when I try and do findViewById it returns null.

Below is the code.

MenuItem mnuUpgrade;
    mnuUpgrade = (MenuItem)findViewById(R.id.mnu_upgrade);
            if (common.checkForProVersion())
            {
                //mnuUpgrade.setVisible(false);
            }
            else
            {
                //mnuUpgrade.setVisible(true);
            }

and below is my XML file

<?xml version="1.0" encoding="utf-8"?>
<menu xmlns:android="http://schemas.android.com/apk/res/android" >
    <item android:id="@+id/mnu_addLogin"
        android:title="New Login"
        android:icon="@android:drawable/ic_menu_add"
        android:showAsAction="always">
    </item>
    <item android:id="@+id/mnu_search"
        android:title="Search"
        android:icon="@android:drawable/ic_menu_search"
        android:showAsAction="always">
    </item>
    <item android:id="@+id/mnu_settings"
        android:title="Settings"
        android:showAsAction="ifRoom"
        android:icon="@android:drawable/ic_menu_manage">
    </item>
    <item android:id="@+id/mnu_upgrade"
        android:title="Upgrade"
        android:showAsAction="ifRoom"
        android:icon="@android:drawable/ic_menu_upload">
    </item>
    <item android:id="@+id/mnu_logout"
        android:title="Log out"
        android:showAsAction="ifRoom"
        android:icon="@android:drawable/ic_menu_close_clear_cancel">
    </item>
</menu>

Thanks for any help you can provide.

  • 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-16T06:20:52+00:00Added an answer on June 16, 2026 at 6:20 am

    The findViewById can’t find a MenuItem. You can use the onPrepareOptionsMenu in your activity. It’s called when user tries to open the menu. You can try this:

    @Override
    public boolean onPrepareOptionsMenu (Menu menu) {
        MenuItem item = menu.getItem(3);
        // the number is the position of your "upgrade" item in the menu, starting from 0
        // then check for the pro version
        if(common.checkForProVersion()) {
            item.setVisible(false);
        } else {
            item.setVisible(true);
        }
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I am currently working on an android project and I am having an issue
I'm currently working on debugging some code with my android project. I'm having an
hi im currently working on my android mediaplayer project , everything was fine but
I am currently working on an android project and I am having a problem
I am currently working on an Android project in Eclipse and i am having
I was currently working on my android project when I came across this issue
I am currently working on a project to automatically generate very simple Android apps
I am currently working on android project where I am using a custom list
I am currently working on android project where I want to have a text
I am currently working on an android project which lists all of the apps

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.