Guilherme
Guilherme

Reputation: 7949

App crash when Menu button is pressed on Android 2.3

My app has an ActionBar (using Support v7 lib) and there are some actions I'd like to add using the Options menu. I followed this tutorial to implement the bar and the menu, and they appear as expected when the view loads.

The device I'm using to test can fit up to 2 buttons in the action bar, while the remaining should go to the overflow menu.

If I add only two items to the menu, when I press the menu button, nothing will happen, which is fine, since there are no more options to be shown;

If I add a 3rd one, or force one not to be shown on the Action Bar (by setting showAsAction="never"), and then I press the Menu button, my app will crash.

Logcat does not register any error messages, but shows these warnings when I press the Menu button:

W/KeyCharacterMap﹕ Can't open keycharmap file
W/KeyCharacterMap﹕ Error loading keycharmap file '/system/usr/keychars/ft5x0x_ts.kcm.bin'. hw.keyboards.65536.devname='ft5x0x_ts'
W/KeyCharacterMap﹕ Using default keymap: /system/usr/keychars/qwerty.kcm.bin

Full log from app initialization until crash moment: http://pastebin.com/gm22H18s

These warnings appear everytime I press the button, regardless which app is running, so I'd say this is unrelated. The downside is that this is the only output on Logcat.

Update: my test device runs Android 2.3 and the app is crashing when I run on it. I tested on a KitKat emulator, and it does not crash on it. I've also tested on a Gingerbread emulator and it also crashes. This way I know my device is not the problem.

menu.xml:

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

<menu xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:com.example.myapp="http://schemas.android.com/apk/res-auto">
    <item
        android:id="@+id/action_search"
        com.example.myapp:showAsAction="always"
        android:icon="@drawable/ic_launcher"
        android:title="Search" />
    <item
        android:id="@+id/menu_cart"
        com.example.myapp:showAsAction="always"
        android:icon="@drawable/ic_launcher"
        android:title="Cart" />
    <item
        android:id="@+id/menu_login"
        com.example.myapp:showAsAction="never"
        android:icon="@drawable/ic_launcher"
        android:title="Log in" />
</menu>

Menu inflation:

@Override
public boolean onCreateOptionsMenu(Menu menu) {
    // Inflate the menu items for use in the action bar
    MenuInflater inflater = getMenuInflater();
    inflater.inflate(R.menu.menu, menu);
    return super.onCreateOptionsMenu(menu);
}

Logcat output:

I/ActivityManager( 277): Start proc com.example.myapp for activity com.example.myapp/.MainActivity: pid=13924 uid=10053 gids={1006, 3003, 1015} W/KeyCharacterMap(13924): Can't open keycharmap file W/KeyCharacterMap(13924): Error loading keycharmap file '/system/usr/keychars/ft5x0x_ts.kcm.bin'. hw.keyboards.65536.devname='ft5x0x_ts' W/KeyCharacterMap(13924): Using default keymap: /system/usr/keychars/qwerty.kcm.bin I/DEBUG (13893): Build fingerprint: 'sprd/sprdroid_base/hsdroid:2.3.5/MocorDroid2.3.5/W12.20_P20.01:user/test-keys' I/DEBUG (13893): pid: 13924, tid: 13924 >>> com.example.myapp <<< I/DEBUG (13893): signal 11 (SIGSEGV), code 1 (SEGV_MAPERR), fault addr 00000001 I/DEBUG (13893): r0 00000000 r1 00000007 r2 fffffe84 r3 00000070 I/DEBUG (13893): r4 0000bca8 r5 40789b38 r6 ad3889dc r7 00000001 I/DEBUG (13893): r8 003a8d98 r9 003a2e60 10 00000001 fp 41968b08 I/DEBUG (13893): ip ad389828 sp befc5358 lr ad356e9d pc a81155c8 cpsr 20800030 I/DEBUG (13893): d0 0000000000000000 d1 0000000000000000 I/DEBUG (13893): d2 0000000000000000 d3 0000000000000000 I/DEBUG (13893): d4 0000000000000000 d5 0000000000000000 I/DEBUG (13893): d6 0000000000000000 d7 0000000000000000 I/DEBUG (13893): d8 0000000042900000 d9 0000000000000000 I/DEBUG (13893): d10 0000000000000000 d11 0000000000000000 I/DEBUG (13893): d12 0000000000000000 d13 0000000000000000 I/DEBUG (13893): d14 0000000000000000 d15 0000000000000000 I/DEBUG (13893): d16 003a8d9860000013 d17 003a2e6000000001 I/DEBUG (13893): d18 000000060053b820 d19 00000001003a2e60 I/DEBUG (13893): d20 ab20faa000000006 d21 ab142fdcbefc5248 I/DEBUG (13893): d22 0000000000000000 d23 0000000000000000 I/DEBUG (13893): d24 3ff0000000000000 d25 0000000000000000 I/DEBUG (13893): d26 0000000000000000 d27 0000000000000000 I/DEBUG (13893): d28 3f137c749114f9db d29 3ff0000000000000 I/DEBUG (13893): d30 0000000000000000 d31 3ff0000000000000 I/DEBUG (13893): scr 60000013 I/DEBUG (13893): I/DEBUG (13893): #00 pc 000155c8 /system/lib/libutils.so I/DEBUG (13893): #01 lr ad356e9d /system/lib/libandroid_runtime.so

Upvotes: 1

Views: 905

Answers (1)

oleonardomachado
oleonardomachado

Reputation: 104

Same problem here. It was ok and suddenly stoped. Found the answer at this post

Menu button crashes application when has overflow actions on API 7

It was a problem with 0.9.1 graddle PNG cruncher.

Upvotes: 1

Related Questions