打开崩溃选项菜单时, [英] Crash when opening Option Menu

查看:309
本文介绍了打开崩溃选项菜单时,的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个选项菜单,这是我这个code创建正常活动:

I have ordinary activity with Option Menu, which I created by this code:

@Override
public boolean onCreateOptionsMenu(Menu menu) {
  menu.add(0, 1, 0, "A");
  menu.add(0, 2, 0, "B");
  menu.add(0, 3, 0, "C");
  return true;
}

在Android 2.3及以上(2.2,2.1)是一切正常。但是,当我在Android 4.0上运行这个程序(ICS - 模拟器,Galaxy Nexus的的Nexus S),当我preSS菜单按钮的应用程序crashdown与此异常:

On Android 2.3 and older (2.2, 2.1) is everything fine. But when I run this app on Android 4.0 (ICS - emulator, Galaxy Nexus, Nexus S) when I press menu button the app crashdown with this exception:

W/ResourceType(9263): Failure getting entry for 0x01090044 (t=8 e=68) in package 0 (error -75)
D/AndroidRuntime(9263): Shutting down VM
W/dalvikvm(9263): threadid=1: thread exiting with uncaught exception (group=0x40a4a1f8)
FATAL EXCEPTION: main
android.content.res.Resources$NotFoundException: Resource ID #0x1090044
E/AndroidRuntime(9263):
at android.content.res.Resources.getValue(Resources.java:1019)
at android.content.res.Resources.loadXmlResourceParser(Resources.java:2107)
at android.content.res.Resources.getLayout(Resources.java:858)
at android.view.LayoutInflater.inflate(LayoutInflater.java:394)
at com.android.internal.view.menu.BaseMenuPresenter.getMenuView(BaseMenuPresenter.java:70)
at com.android.internal.policy.impl.PhoneWindow$PanelFeatureState.getIconMenuView(PhoneWindow.java:3298)
at com.android.internal.policy.impl.PhoneWindow.initializePanelContent(PhoneWindow.java:1096)
at com.android.internal.policy.impl.PhoneWindow.openPanel(PhoneWindow.java:559)
at com.android.internal.policy.impl.PhoneWindow.onKeyUpPanel(PhoneWindow.java:817)
at com.android.internal.policy.impl.PhoneWindow.onKeyUp(PhoneWindow.java:1486)
at com.android.internal.policy.impl.PhoneWindow$DecorView.dispatchKeyEvent(PhoneWindow.java:1813)
at android.view.ViewRootImpl.deliverKeyEventPostIme(ViewRootImpl.java:3300)
at android.view.ViewRootImpl.handleFinishedEvent(ViewRootImpl.java:3273)
at android.view.ViewRootImpl.handleMessage(ViewRootImpl.java:2436)
at android.os.Handler.dispatchMessage(Handler.java:99)
at android.os.Looper.loop(Looper.java:137)
at android.app.ActivityThread.main(ActivityThread.java:4340)
at java.lang.reflect.Method.invokeNative(Native Method)
at java.lang.reflect.Method.invoke(Method.java:511)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:784)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:551)
at dalvik.system.NativeStart.main(Native Method)

我无法与ID#0x1090044本地化资源(这不是我的R.java或任何其他文件),我不知道它应该是什么。也许一些内部菜单布局?我已经还试图清理项目。
我知道有新的德兴规则为Android 4.0 ICS和使用操作栏,而不是旧的菜单,但我需要这个code得到ICS许多不同的原因,甚至工作。应我一些如何编辑这个code甚至在ICS工作?
我也已经尝试过使用这种code具有相同的异常从XML文件中创建菜单。

I can't localize resource with ID #0x1090044 (it's not in my R.java or any other files) and I don't know what it should be. Maybe some internal menu layout? I already also tried to clean the project. I know that there are new "desing rules" for Android 4.0 ICS and using Action Bar instead older menu, but I need this code get working even on ICS for many different reasons. Should I some how edit this code to work even on ICS? I also already tried creating menu from XML file using this code with same exception.

MenuInflater inflater = getMenuInflater();
inflater.inflate(R.menu.menu, menu);

感谢您的任何建议!

推荐答案

终于来了!的问题是在一些略有不同。我就是用这个code:

Finally! The problem was in something slightly different. I was using this code:

Resources standardResources = getResources();
AssetManager assets = standardResources.getAssets();
DisplayMetrics metrics = standardResources.getDisplayMetrics();
Configuration config = new Configuration(); 
// CORRECT is: Configuration config = standardResources.getConfiguration();
config.locale = new Locale(lang);
Resources defaultResources = new Resources(assets, metrics, config);

我之前没有因为2.3检查code的这一错误路线,少一切都很好。但是,现在的4.0东西在内部资源被改变。我不知道这是否是某种类型的错误(我打电话这个code多次在我的活动,但只有当我使用选项菜单引发错误),但肯定有我的$的bug C $角

I didn't check this wrong line of code before because on 2.3 and less everything was fine. But now on 4.0 something was changed in internal resources. I don't know if it is some sort of bug (I'm calling this code for many times in my Activity but only when I use Options menu error is raised), but for sure there was the bug in my code.

这篇关于打开崩溃选项菜单时,的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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