单击菜单后没有显示?

内容来源于 Stack Overflow,并遵循CC BY-SA 3.0许可协议进行翻译与使用

  • 回答 (1)
  • 关注 (0)
  • 查看 (101)

我试图在我的应用程序中创建一个菜单,但是当我运行我的应用程序时,会出现一个错误,当我点击菜单时,这个错误就会消失,如何纠正它?请帮助我。下面是显示菜单代码的错误

        <?xml version="1.0" encoding="utf-8"?>
       <menu xmlns:android="http://schemas.android.com/apk/res/android"
        xmlns:app="http://schemas.android.com/apk/res-auto">
       <item
       android:id="@+id/meu_showmsg"
       android:icon="@drawable/menuh"
       android:state_pressed="true"
       android:title="@string/se_connecter"
       app:showAsAction="always" />

      </menu>

代码活动

        @Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_home);
}

@Override
public boolean onOptionsItemSelected(MenuItem item) {
    switch (item.getItemId()) {
        case R.id.meu_showmsg:
            new MaterialDialog.Builder(this)
                    .title("Se connecter").show();
            break;

    }
    return super.onOptionsItemSelected(item);
}

@Override
public boolean onCreateOptionsMenu(Menu menu) {

   getMenuInflater().inflate(R.menu.bein_markt_menu, menu);
    return super.onCreateOptionsMenu(menu);
}
}

logcat

 E/AndroidRuntime: FATAL EXCEPTION: main
              Process: zied.aloui.beinmarkt, PID: 3780
              android.content.res.Resources$NotFoundException: Resource ID #0x7f060063
                  at android.content.res.Resources.getValue(Resources.java:1351)
                  at android.support.v7.widget.AppCompatDrawableManager.loadDrawableFromDelegates(AppCompatDrawableManager.java:328)
                  at android.support.v7.widget.AppCompatDrawableManager.getDrawable(AppCompatDrawableManager.java:193)
                  at android.support.v7.widget.AppCompatDrawableManager.getDrawable(AppCompatDrawableManager.java:186)
                  at android.support.v7.content.res.AppCompatResources.getDrawable(AppCompatResources.java:100)
                  at android.support.v7.view.menu.MenuItemImpl.getIcon(MenuItemImpl.java:491)
                  at android.support.v7.view.menu.ActionMenuItemView.initialize(ActionMenuItemView.java:125)
                  at android.support.v7.widget.ActionMenuPresenter.bindItemView(ActionMenuPresenter.java:210)
                  at android.support.v7.view.menu.BaseMenuPresenter.getItemView(BaseMenuPresenter.java:187)
                  at android.support.v7.widget.ActionMenuPresenter.getItemView(ActionMenuPresenter.java:196)
                  at android.support.v7.widget.ActionMenuPresenter.flagActionItems(ActionMenuPresenter.java:476)
                  at android.support.v7.view.menu.MenuBuilder.flagActionItems(MenuBuilder.java:1164)
                  at android.support.v7.view.menu.BaseMenuPresenter.updateMenuView(BaseMenuPresenter.java:95)
                  at android.support.v7.widget.ActionMenuPresenter.updateMenuView(ActionMenuPresenter.java:229)
                  at android.support.v7.view.menu.MenuBuilder.dispatchPresenterUpdate(MenuBuilder.java:291)
                  at android.support.v7.view.menu.MenuBuilder.onItemsChanged(MenuBuilder.java:1051)
                  at android.support.v7.view.menu.MenuBuilder.startDispatchingItemsChanged(MenuBuilder.java:1078)
                  at android.support.v7.app.AppCompatDelegateImplV9.preparePanel(AppCompatDelegateImplV9.java:1419)
                  at android.support.v7.app.AppCompatDelegateImplV9.doInvalidatePanelMenu(AppCompatDelegateImplV9.java:1657)
                  at android.support.v7.app.AppCompatDelegateImplV9$1.run(AppCompatDelegateImplV9.java:134)
                  at android.os.Handler.handleCallback(Handler.java:739)
                  at android.os.Handler.dispatchMessage(Handler.java:95)
                  at android.os.Looper.loop(Looper.java:148)
                  at android.app.ActivityThread.main(ActivityThread.java:5417)
                  at java.lang.reflect.Method.invoke(Native Method)
                  at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:726)
                  at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:616)
提问于
用户回答回答于

这个:

android.content.res.Resources$NotFoundException: Resource ID #0x7f060063

以及这个:

at android.support.v7.view.menu.MenuItemImpl.getIcon(MenuItemImpl.java:491)

表示可能不存在用于菜单的其中一个图标,也许你拼错了它。

所属标签

可能回答问题的人

  • uncle_light

    5 粉丝518 提问8 回答
  • 嗨喽你好

    7 粉丝480 提问8 回答
  • 人生的旅途

    10 粉丝484 提问7 回答
  • 无聊至极

    4 粉丝504 提问6 回答

扫码关注云+社区

领取腾讯云代金券