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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 6, 20262026-06-06T03:23:00+00:00 2026-06-06T03:23:00+00:00

I am a new bee to Android App Development . I am practicing the

  • 0

I am a new bee to Android App Development. I am practicing the code in the Book Hello, Android . Right now I am struck with Menu and could not able to move further. I would like to present my situation in clear so that I could be guided by an experienced android app developer . I uploaded a picture showing the status.
when I pressed the menu I could able to find one option called settings.

But nothing happens when the settings button is pressed. I am surprised about the error and wasted lot of time to fix it. but I could not able to fix it. I want some real android app development professional to find the solution to this problem that I face and help me to proceed further.

enter image description here

here is the code that i used.

test/src/org/anil/test/TestActivity.java

    package org.anil.test;

    import android.app.Activity;
    import android.os.Bundle;
    import android.view.Menu;
    import android.view.MenuInflater;
    import android.view.MenuItem;
    import android.content.Intent;

    public class TestActivity extends Activity {
    /** Called when the activity is first created. */
     @Override
    public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.main);
    }

    public boolean onCreateOptionsMenu(Menu menu){
    super.onCreateOptionsMenu(menu);
    MenuInflater inflater = getMenuInflater();
    inflater.inflate(R.menu.menu, menu);
    return true;
    }
    public boolean onOptionsMenuSelected( MenuItem item){
    switch(item.getItemId()){
    case R.id.settings:
        startActivity(new Intent(this, Prefs.class));
        return true;
    }
    return false;
    }
    }

test/res/layout/main.xml

    <?xml version="1.0" encoding="utf-8"?>

    <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="fill_parent"
    android:layout_height="fill_parent"
    android:orientation="vertical" >

   <TextView
    android:layout_width="fill_parent"
    android:layout_height="wrap_content"
    android:text="@string/hello" />

    </LinearLayout>

test/src/org/anil/test/Prefs.java

    package org.anil.test;
    import android.os.Bundle;
    import android.preference.PreferenceActivity;

    public class Prefs extends PreferenceActivity {
    protected void onCreate(Bundle savedInstanceState){
    super.onCreate(savedInstanceState);
    addPreferencesFromResource(R.xml.settings);
    }

    }

test/res/menu/menu.xml

    <?xml version="1.0" encoding="UTF-8"?>
    <menu xmlns:android="http://schemas.android.com/apk/res/android">
    <item 
        android:id="@+id/settings"
        android:title="@string/settings_label"
        android:alphabeticShortcut="@string/settings_shortcut" />
    </menu>

test/res/xml/settings.xml

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

    <CheckBoxPreference 
    android:key="music"
    android:title="@string/music_title"
    android:summary="@string/music_summary" 
    android:defaultValue="true" />

    <CheckBoxPreference 
    android:key="hints"
    android:title="@string/hints_title"
    android:summary="@string/hints_summary" 
    android:defaultValue="true"/>

    </PreferenceScreen>

test/res/values/strings.xml

    <?xml version="1.0" encoding="utf-8"?>
    <resources>

    <string name="hello">Hello World, TestActivity!</string>
    <string name="app_name">Test</string>
    <string name="settings_label">Settings</string>
    <string name="settings_title">Sudoku Settings</string>
    <string name="settings_shortcut">s</string>
    <string name="music_title">Music</string>
    <string name="music_summary">play background music</string>
    <string name="hints_title">Hints</string>
    <string name="hints_summary">Show hints during play</string>

    </resources>

test/AndroidManifest.xml

    <?xml version="1.0" encoding="utf-8"?>
    <manifest xmlns:android="http://schemas.android.com/apk/res/android"
    package="org.anil.test"
    android:versionCode="1"
    android:versionName="1.0" >

    <uses-sdk android:minSdkVersion="10" />

    <application
    android:icon="@drawable/ic_launcher"
    android:label="@string/app_name" >
    <activity
        android:name=".TestActivity"
        android:label="@string/app_name" >
        <intent-filter>
            <action android:name="android.intent.action.MAIN" />

            <category android:name="android.intent.category.LAUNCHER" />
        </intent-filter>
    </activity>

    <activity android:name=".Prefs" android:label="@string/settings_title">
    </activity>

    </application>

    </manifest>
  • 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-06T03:23:01+00:00Added an answer on June 6, 2026 at 3:23 am

    The name of method for callback for menu selection is onOptionsItemSelected() instead of onOptionsMenuSelected(), try this way:

    @Override
    public boolean onOptionsItemSelected (MenuItem item)
    {
        //Your code implementation
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Hello I am new bee to the iphone apps development is there a way
I am new bee in Android , so the knowledge regarding android is not
Hello Everyone I'm really new bee in android and for that I'm confused to
I'm a new bee in JFace. My table viewer alloc code is: viewer =
I m a new bee to Android world. I have a listview which has
I am new bee in ANDROID , so for that I am unable to
I am new bee in Android, so for that I have only limited knowledge
I am new bee in ANDROID so am getting problem in retrieving data especially
I am new bee to android and stack overflow too. I am developing an
Hi i'm new bee to android. while executing my application I'm getting nullpoint exception

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.