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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 22, 20262026-05-22T17:53:00+00:00 2026-05-22T17:53:00+00:00

So I have a menu inflator and when I select something in it, my

  • 0

So I have a menu inflator and when I select something in it, my program force closes and I believe it is because the class also implements onclicklistener for an array of buttons I have to add. Here is some of the relevant code:

    package com.riley.howmany;

import android.app.Activity;
import android.content.Context;
import android.content.Intent;
import android.os.Bundle;
import android.widget.ScrollView;
import android.widget.LinearLayout;
import android.widget.Button;
import android.widget.TextView;
import android.widget.Toast;
import android.view.Menu;
import android.view.MenuInflater;
import android.view.MenuItem;
import android.view.View;
import android.view.View.OnClickListener;

public class howMany extends Activity implements View.OnClickListener{
    /** Called when the activity is first created. */
    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
//I have to use a dynamic layout because it changes based on user options.
//As of right now it is just in a for loop because the settings menu won't open
//because of this issue. I hope this makes sense.
        ScrollView sv = new ScrollView(this);
        LinearLayout ll = new LinearLayout(this);
        ll.setOrientation(LinearLayout.VERTICAL);
        sv.addView(ll);
        ll.setPadding(1,1,1,1);

        TextView tv = new TextView(this);
        tv.setText("Dynamic layouts ftw!");
        ll.addView(tv);
//Each button press actually performs the same code for that individual button
        for (int c=0; c<=10; c++) {
            Button b = new Button (this);
            b.setText("Button:"+" "+"0");
            b.setTextSize(10.0f);
            b.setOnClickListener(this);
            ll.addView(b);
        }

        this.setContentView(sv);
    }

    public void onClick(View view) {
        //handle each button click
    }


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

    @Override
    public boolean onOptionsItemSelected(MenuItem item) {
        Intent intent = new Intent(this, Setting.class);
        startActivity(intent);

        return true;

    }
}

Thank you very much for any advice you can provide!

EDIT/UPDATE!

Ok I found the fix. Here it is:

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

@Override
public boolean onOptionsItemSelected (MenuItem item) {
            startActivity(new Intent(this, Setting.class));
            return true;
    }

Now it works great! Thank you for the help.

  • 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-22T17:53:01+00:00Added an answer on May 22, 2026 at 5:53 pm

    Your onClick listener shouldn’t be the problem.
    The force close can come from your startActivity() call.
    Are you sure you have declared the Setting activity in your manifest?

    Could you post your whole manifest?

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

Sidebar

Related Questions

I have a Menu class that has a IQueryable property called WebPages. In the
i have menu structure like below <ul class=menu_bg id=menu-main-menu> <li class=menu-item menu-item-type-post_type menu-item-object-page menu-item-653
I have an options menu in an Activity with three MenuItems create select delete
I have class that extends Activity. That has a Logout menu options. When I
I have a menu running off of a sitemap which one of the SiteMapNode
I have a menu control inside of an updatepanel. When I hover over a
I have a menu with an animation going on, but I want to disable
I have a menu div that I want to slide down so it's always
I have a menu of product brands that I want to split over 4
I have a menu of report links in my master page. I need to

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.