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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 3, 20262026-06-03T09:53:26+00:00 2026-06-03T09:53:26+00:00

My app runs great on the ICS emu. However, using Gingerbread, it crashes whenever

  • 0

My app runs great on the ICS emu. However, using Gingerbread, it crashes whenever my onCreateOptionsMenu is in use. It also throws another, similar but different set of errors if I use showPopup instead. Does anyone know what exactly is going on here? Ideally, I would like to have one bit of menu code (excluding the listener, of course) that will lay out a menu for all versions of android running the app. I should mention, though, that I have a GUI menu button (sitting in my XML file as an ImageView), rather than one in the ActionBar. So, here’s the code:

public boolean onCreateOptionsMenu(Menu menu) {
    MenuInflater inflater = getMenuInflater();
    inflater.inflate(R.menu.main_menu, menu);
    return true;

}

Here’s the menu XML:

<?xml version="1.0" encoding="utf-8"?>
<menu xmlns:android="http://schemas.android.com/apk/res/android">
        <item android:id="@+id/demographics"
              android:title="@string/demographics" />
        <item android:id="@+id/tabSelection"
              android:title="@string/tabs" />            
        <item android:id="@+id/settings"
              android:title="@string/settings" />


</menu>

And here’s the LogCat:

threadid=1: thread exiting with uncaught exception (group=0x40015560)
FATAL EXCEPTION: main
java.lang.IllegalStateException: Cannot interact with object designed for temporary instance passing. Make sure you using both SherlockFragmentActivity and SherlockFragment.
at com.actionbarsherlock.internal.view.menu.MenuMule.add(MenuMule.java:40)
at android.view.MenuInflater$MenuState.addItem(MenuInflater.java:310)
at android.view.MenuInflater.parseMenu(MenuInflater.java:154)
at android.view.MenuInflater.inflate(MenuInflater.java:80)
at com.davekelley.polling.Polling.onCreateOptionsMenu(Polling.java:203)
at android.app.Activity.onCreatePanelMenu(Activity.java:2158)
at android.support.v4.app.FragmentActivity.onCreatePanelMenu(FragmentActivity.java:209)
at com.actionbarsherlock.app.SherlockFragmentActivity.onCreatePanelMenu(SherlockFragmentActivity.java:236)
at com.actionbarsherlock.ActionBarSherlock.callbackCreateOptionsMenu(ActionBarSherlock.java:543)
at com.actionbarsherlock.internal.ActionBarSherlockCompat.preparePanel(ActionBarSherlockCompat.java:467)
at com.actionbarsherlock.internal.ActionBarSherlockCompat.dispatchInvalidateOptionsMenu(ActionBarSherlockCompat.java:269)
at com.actionbarsherlock.internal.ActionBarSherlockCompat$1.run(ActionBarSherlockCompat.java:972)
at android.os.Handler.handleCallback(Handler.java:587)
at android.os.Handler.dispatchMessage(Handler.java:92)
at android.os.Looper.loop(Looper.java:123)
at android.app.ActivityThread.main(ActivityThread.java:3683)
at java.lang.reflect.Method.invokeNative(Native Method)
at java.lang.reflect.Method.invoke(Method.java:507)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:839)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:597)
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-06-03T09:53:27+00:00Added an answer on June 3, 2026 at 9:53 am

    So basically in order to complete this, I can’t use showPopup because that’s only on API 11 and up.

    I had so much trouble trying to get it all to work properly on the older versions of Android due, at least partially, to some incongruities with ActionBarSherlock that I didn’t fully understand. Which imports I used were very important to getting the app to launch without crashes, here they are:

    import com.actionbarsherlock.view.Menu;
    import com.actionbarsherlock.view.MenuInflater;
    import com.actionbarsherlock.view.MenuItem;

    Beyond that, I found another Stack Overflow post that highlighted the method openOptionsMenu. So in my fragment, I add an onClickListener for my menuButton ImageView. When the user taps that, the main activity is told to openOptionsMenu, which runs onCreateOptionsMenu. Right now the onMenuItemClick method doesn’t seem to be doing its job, but I think I’ll be able to sort that out fairly quickly tomorrow. There is one difference to how the menu used to load now though. Rather than popping up right on top of the ImageView, it loads on the bottom of the screen (in either the old way, or the new vertical menu in ICS). So there’s that, but it’s not a big problem.

    I think that just about covers it.

    Code:

        ImageView menuImg = (ImageView) activity.findViewById(R.id.menuImageView);
        menuImg.setOnClickListener(new OnClickListener() {
            public void onClick(View v) {
                activity.openOptionsMenu();
            }
        });
    

    public boolean onCreateOptionsMenu(Menu menu) {
        MenuInflater inflater = getSupportMenuInflater();
        inflater.inflate(R.menu.main_menu, menu);
        return true;    
    }
    

    public boolean onMenuItemClick(MenuItem item) {
         switch (item.getItemId()) {
            case R.id.demographics:
    
                return true;
            case R.id.settings:
                Log.v("v", "settings clicked");
                return true;
            default:
                return false;
         }
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

My app runs fine in development mode. When I run in production mode using
I am encountering a strange behaviour, my app runs smoothly on simulator but crashes
My app runs great in the simulator, and has been working great on device
In my app I am using an Icon Pack Specifically This One. I use
I am developing an application using WPF. The app runs full screen, and I
I've been using Ninject as my IOC in my web app. It's great and
I'm developing an iOS app for iPhone and iPad. It runs great on the
Background: I developed a web app in ASP.Net 3.5 in C#. It runs great
I had a problem with my iPhone app runs on iPad .I am using
My app runs fine on first run. Then when I terminate it and run

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.