Android:什么会导致“选项菜单"膨胀错误? [英] Android: What could cause an Options Menu inflation error?

查看:129
本文介绍了Android:什么会导致“选项菜单"膨胀错误?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

当我按下菜单按钮并在onCreateOptionsMenu方法中添加菜单项时,出现膨胀错误.我在下面列出了一些错误.

I am receiving an inflation error when pressing the Menu button and adding a menu item in the onCreateOptionsMenu method. I've included some of the error below.

代码如下,如果我单独尝试而不是整个活动的一部分,它可以工作.我认为在此处粘贴整个活动是不可行的(我不知道是哪个原因引起的),所以想知道以前是否有人经历过此事?

The code is as follows, and works if I try it on its own and not as part of my activity as a whole. I don't think it's feasible to paste in the whole of my activity here (I have no idea which bit could be causing this), so am wondering if anyone has experienced this before?

public boolean onCreateOptionsMenu(Menu m) {
    Log.d(TAG, "Menu Create");
    this.menu = m;
    m.add(0, 0, 0, "HAZAH!");
    return true;
}


05-24 17:18:47.963: ERROR/AndroidRuntime(1658): android.view.InflateException: Binary XML file line #17: Error inflating class com.android.internal.view.menu.IconMenuItemView 05-24 17:18:47.963: ERROR/AndroidRuntime(1658): at android.view.LayoutInflater.createView(LayoutInflater.java:513) 05-24 17:18:47.963: ERROR/AndroidRuntime(1658): at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:565) 05-24 17:18:47.963: ERROR/AndroidRuntime(1658): at android.view.LayoutInflater.inflate(LayoutInflater.java:385)


05-24 17:18:47.963: ERROR/AndroidRuntime(1658): android.view.InflateException: Binary XML file line #17: Error inflating class com.android.internal.view.menu.IconMenuItemView 05-24 17:18:47.963: ERROR/AndroidRuntime(1658): at android.view.LayoutInflater.createView(LayoutInflater.java:513) 05-24 17:18:47.963: ERROR/AndroidRuntime(1658): at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:565) 05-24 17:18:47.963: ERROR/AndroidRuntime(1658): at android.view.LayoutInflater.inflate(LayoutInflater.java:385)

05-24 17:18:47.963: ERROR/AndroidRuntime(1658): Caused by: java.lang.reflect.InvocationTargetException 05-24 17:18:47.963: ERROR/AndroidRuntime(1658): at com.android.internal.view.menu.IconMenuItemView.<init>(IconMenuItemView.java:86)

05-24 17:18:47.963: ERROR/AndroidRuntime(1658): Caused by: java.lang.reflect.InvocationTargetException 05-24 17:18:47.963: ERROR/AndroidRuntime(1658): at com.android.internal.view.menu.IconMenuItemView.<init>(IconMenuItemView.java:86)

05-24 17:18:47.963: ERROR/AndroidRuntime(1658): Caused by: java.lang.reflect.InvocationTargetException 05-24 17:18:47.963: ERROR/AndroidRuntime(1658): at com.android.internal.view.menu.IconMenuItemView.<init>(IconMenuItemView.java:86)

05-24 17:18:47.963: ERROR/AndroidRuntime(1658): Caused by: java.lang.reflect.InvocationTargetException 05-24 17:18:47.963: ERROR/AndroidRuntime(1658): at com.android.internal.view.menu.IconMenuItemView.<init>(IconMenuItemView.java:86)

如果我尝试在连接调试器的情况下按菜单,我会看到它在此处停止:

If I try pressing Menu with the debugger attached I see it stop here:

Suspended (exception InflateException)
ViewRoot.deliverKeyEventToViewHierarchy(KeyEvent, boolean) line: 2425   

谢谢.

推荐答案

之所以发生这种情况,是因为我为活动分配了一个主题,其中包含以下行:

This was occurring as I had assigned a theme to the Activity which contained the following line:

<item name="android:text"></item>

我使用它来删除标题栏中的应用名称文本.我猜这不是正确的方法!幸运的是,这是对我的应用程序的最新更改之一,因此我能够(最终)对其进行跟踪.

I was using this to remove the app name text in the title bar. I guess this isn't the right way to do it! Luckily this was one of the recent changes to my app so I was able to track it down (eventually).

这篇关于Android:什么会导致“选项菜单"膨胀错误?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆