gpt4 book ai didi

Android,OptionMenu ResourceNotFoundException;当切换到陆地空间

转载 作者:行者123 更新时间:2023-11-30 02:13:44 29 4
gpt4 key购买 nike

当我的 android 应用程序以纵向屏幕启动时,操作栏中有选项菜单;但是当切换到 landspace 时,我发现资源未找到异常。 inflater.inflate(R.menu.main, menu) 异常;

为什么我会收到这个错误,谢谢

这是我的代码

@Override
public boolean onCreateOptionsMenu(Menu menu) {

// Inflate the menu items for use in the action bar
MenuInflater inflater = getMenuInflater();
try {
inflater.inflate(R.menu.main, menu); //Exception is here
}
catch(Exception ex){

return super.onCreateOptionsMenu(menu);
}

// Here we get the action view we defined
menuItem = menu.findItem(R.id.action_search);
View actionView = menuItem.getActionView();

// We then get the edit text view that is part of the action view
if (actionView != null) {
etActionSearch = (AutoCompleteTextView) actionView.findViewById(R.id.myActionEditText);

if (etActionSearch != null) {
// We set a listener that will be called when the return/enter key is pressed
etActionSearch.setOnEditorActionListener(this);

}

菜单

<menu xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto">
<item android:id="@+id/action_search"
android:icon="@drawable/action_search"
android:title="Search"
app:showAsAction="ifRoom|collapseActionView"
android:actionLayout="@layout/action_search_singlerow" />
<item
android:id="@+id/action_changeview"
android:title="Change View"
android:icon="@drawable/action_changeviewlist"
app:showAsAction="ifRoom|collapseActionView"
/>
<item
android:id="@+id/action_refresh"
android:icon="@drawable/action_refresh"
app:showAsAction="ifRoom|collapseActionView"
android:title="Refresh"/>
<item
android:id="@+id/action_sorting"
android:title="Sort"
android:icon="@drawable/action_sorting"
app:showAsAction="ifRoom|collapseActionView"
/>

异常

android.content.res.Resources$NotFoundException: Resource ID #0x7f0e0002
at android.content.res.Resources.getValue(Resources.java:1143)
at android.content.res.Resources.loadXmlResourceParser(Resources.java:2385)
at android.content.res.Resources.getLayout(Resources.java:959)
at android.view.MenuInflater.inflate(MenuInflater.java:107)
at com.test.test.MainActivity.onCreateOptionsMenu(MainActivity.java:238)
at android.app.Activity.onCreatePanelMenu(Activity.java:2571)
at com.android.internal.policy.impl.PhoneWindow.preparePanel(PhoneWindow.java:451)
at com.android.internal.policy.impl.PhoneWindow.doInvalidatePanelMenu(PhoneWindow.java:826)
at com.android.internal.policy.impl.PhoneWindow$1.run(PhoneWindow.java:236)
at android.os.Handler.handleCallback(Handler.java:808)
at android.os.Handler.dispatchMessage(Handler.java:103)
at android.os.Looper.loop(Looper.java:193)
at android.app.ActivityThread.main(ActivityThread.java:5307)
at java.lang.reflect.Method.invokeNative(Native Method)
at java.lang.reflect.Method.invoke(Method.java:515)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:831)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:647)
at dalvik.system.NativeStart.main(Native Method)

最佳答案

事实证明,OP 在菜单布局文件中使用了仅在布局端口文件夹中定义的 XML 布局,因此发生了崩溃。他添加了相同布局的 layout-land 版本并解决了这个问题。

关于Android,OptionMenu ResourceNotFoundException;当切换到陆地空间,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/29723374/

29 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com