I am getting this error on inflating the menu
Logcat:
android.view.InflateException: Binary XML file line #17: Error inflating class android.support.v7.internal.view.menu.ActionMenuItemView
at android.view.LayoutInflater.createView(LayoutInflater.java:620)
at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:696)
at android.view.LayoutInflater.inflate(LayoutInflater.java:469)
at android.view.LayoutInflater.inflate(LayoutInflater.java:397)
at android.support.v7.internal.view.menu.BaseMenuPresenter.createItemView(BaseMenuPresenter.java:161)
at android.support.v7.internal.view.menu.BaseMenuPresenter.getItemView(BaseMenuPresenter.java:180)
at android.support.v7.widget.ActionMenuPresenter.getItemView(ActionMenuPresenter.java:170)
at android.support.v7.widget.ActionMenuPresenter.flagActionItems(ActionMenuPresenter.java:429)
at android.support.v7.internal.view.menu.MenuBuilder.flagActionItems(MenuBuilder.java:1129)
at android.support.v7.internal.view.menu.BaseMenuPresenter.updateMenuView(BaseMenuPresenter.java:91)
at android.support.v7.widget.ActionMenuPresenter.updateMenuView(ActionMenuPresenter.java:207)
at android.support.v7.internal.view.menu.MenuBuilder.dispatchPresenterUpdate(MenuBuilder.java:279)
at android.support.v7.internal.view.menu.MenuBuilder.onItemsChanged(MenuBuilder.java:1021)
at android.support.v7.internal.view.menu.MenuBuilder.startDispatchingItemsChanged(MenuBuilder.java:1044)
at android.support.v7.internal.app.ToolbarActionBar.populateOptionsMenu(ToolbarActionBar.java:465)
at android.support.v7.internal.app.ToolbarActionBar$1.run(ToolbarActionBar.java:69)
at android.os.Handler.handleCallback(Handler.java:733)
at android.os.Handler.dispatchMessage(Handler.java:95)
at android.os.Looper.loop(Looper.java:136)
at android.app.ActivityThread.main(ActivityThread.java:5136)
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:819)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:635)
at dalvik.system.NativeStart.main(Native Method)
This is the menu xml
<menu xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
tools:context="com.example.drawermenu.JavaDrawerActivity" >
<item
android:id="@+id/action_settings"
android:orderInCategory="100"
android:icon="@drawable/ic_launcher"
android:title="@string/action_settings"
app:showAsAction="always"/>
</menu>
This is the java code
@Override
public boolean onCreateOptionsMenu(Menu menu) {
// Inflate the menu; this adds items to the action bar if it is present.
getMenuInflater().inflate(R.menu.java_drawer, menu);
return true;
}
@Override
public boolean onPrepareOptionsMenu(Menu menu) {
// If the nav drawer is open, hide action items related to the content
// view
// boolean drawerOpen = mDrawerLayout.isDrawerOpen(mDrawerList);
// menu.findItem(R.id.action_websearch).setVisible(!drawerOpen);
return super.onPrepareOptionsMenu(menu);
}
@Override
public boolean onOptionsItemSelected(MenuItem item) {
// Handle action bar item clicks here. The action bar will
// automatically handle clicks on the Home/Up button, so long
// as you specify a parent activity in AndroidManifest.xml.
int id = item.getItemId();
if (id == R.id.action_settings) {
return true;
}
if (mDrawerToggle.onOptionsItemSelected(item)) {
return true;
}
return super.onOptionsItemSelected(item);
}
Oncreate
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
mDrawerLayout = new DrawerLayout(getApplicationContext());
mDrawerLayout.setLayoutParams(new DrawerLayout.LayoutParams(
LayoutParams.MATCH_PARENT, LayoutParams.MATCH_PARENT));
mDrawerLayout.setFitsSystemWindows(true);
content_frame = new FrameLayout(getApplicationContext());
content_frame.setLayoutParams(new DrawerLayout.LayoutParams(
LayoutParams.MATCH_PARENT, LayoutParams.MATCH_PARENT));
content_layout = new LinearLayout(getApplicationContext());
content_layout.setOrientation(LinearLayout.VERTICAL);
content_layout.setLayoutParams(new LinearLayout.LayoutParams(
LayoutParams.MATCH_PARENT, LayoutParams.MATCH_PARENT));
content_layout.setBackgroundColor(Color.parseColor("#FFFFFF"));
tool = new Toolbar(getApplicationContext());
LinearLayout.LayoutParams lp = new LinearLayout.LayoutParams(
LayoutParams.MATCH_PARENT, LayoutParams.WRAP_CONTENT);
tool.setLayoutParams(lp);
tool.setBackgroundColor(Color.parseColor("#00BBD3"));
setSupportActionBar(tool);
TypedValue tv = new TypedValue();
if (this.getTheme().resolveAttribute(android.R.attr.actionBarSize, tv,
true)) {
int actionBarHeight = TypedValue.complexToDimensionPixelSize(
tv.data, this.getResources().getDisplayMetrics());
tool.setMinimumHeight(actionBarHeight);
}
getSupportActionBar().setDisplayShowTitleEnabled(true);
getSupportActionBar().setTitle("TOURNAMENTS");
content_layout1 = new LinearLayout(getApplicationContext());
content_layout1.setOrientation(LinearLayout.VERTICAL);
content_layout1.setLayoutParams(new DrawerLayout.LayoutParams(320,
LayoutParams.MATCH_PARENT, Gravity.START));
t = new TextView(getApplicationContext());
t.setTextColor(Color.BLACK);
t.setText("XYZ");
ivBottom = new ImageView(getApplicationContext());
LinearLayout.LayoutParams par = new LinearLayout.LayoutParams(50, 50);
par.gravity = Gravity.CENTER_HORIZONTAL;
ivBottom.setLayoutParams(par);
ivBottom.setBackgroundResource(R.drawable.ic_launcher);
mDrawerList = new ListView(getApplicationContext());
mDrawerList.setLayoutParams(new LinearLayout.LayoutParams(
LayoutParams.MATCH_PARENT, LayoutParams.WRAP_CONTENT));
content_layout1.setBackgroundColor(Color.BLACK);
content_layout.addView(tool);
content_layout.addView(t);
content_frame.addView(content_layout);
mDrawerLayout.addView(content_frame);
content_layout1.addView(mDrawerList);
content_layout1.addView(ivBottom);
mDrawerLayout.addView(content_layout1);
setContentView(mDrawerLayout);
// Set the adapter for the list view
mDrawerList.setAdapter(new SideAdapter(getApplicationContext(),
menuTitles, menuIcons));
// Set the list's click listener
mDrawerList.setOnItemClickListener(new DrawerItemClickListener());
mDrawerToggle = new ActionBarDrawerToggle(this, mDrawerLayout, tool,
R.string.action_settings, R.string.action_settings) {
/** Called when a drawer has settled in a completely closed state. */
public void onDrawerClosed(View view) {
super.onDrawerClosed(view);
invalidateOptionsMenu(); // creates call to
// onPrepareOptionsMenu()
}
/** Called when a drawer has settled in a completely open state. */
public void onDrawerOpened(View drawerView) {
super.onDrawerOpened(drawerView);
invalidateOptionsMenu(); // creates call to
// onPrepareOptionsMenu()
}
};
// Set the drawer toggle as the DrawerListener
mDrawerLayout.setDrawerListener(mDrawerToggle);
}