Когда приложение для Android было запущено на портретном экране, в панели действий есть опции; но когда вы переключаетесь на ландшафт, я получаю исключение ресурса не найденным. Исключение на inflater.inflate (R.menu.main, menu);Android, OptionMenu ResourceNotFoundException; при переключении на ландшафт
Почему я получаю эту ошибку, спасибо
А вот мой код
@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)
Можете ли вы добавить menu.xml? –
Где вы храните файл main.xml в своем проекте? – joao2fast4u
А как насчет вашего макета action_search_singlerow? – joao2fast4u