java - android.view.InflateException: Binary XML file line #17: Error inflating class android.support.design.widget.NavigationView -
i know kind of duplicate question none of suggested answers in other posts helped me in resolving error.so please me in resolving error. know question has lot of code read have post of code guyz can take @ whole code.
my stacktrace :-
e/androidruntime: fatal exception: main process: com.vamediabox.vamediaboxapp, pid: 30915 java.lang.runtimeexception: unable start activity componentinfo{com.vamediabox.vamediaboxapp/com.vamediabox.vamediaboxapp.activities.mainactivity}: android.view.inflateexception: binary xml file line #17: error inflating class android.support.design.widget.navigationview @ android.app.activitythread.performlaunchactivity(activitythread.java:2184) @ android.app.activitythread.handlelaunchactivity(activitythread.java:2233) @ android.app.activitythread.access$800(activitythread.java:135) @ android.app.activitythread$h.handlemessage(activitythread.java:1196) @ android.os.handler.dispatchmessage(handler.java:102) @ android.os.looper.loop(looper.java:136) @ android.app.activitythread.main(activitythread.java:5001) @ java.lang.reflect.method.invokenative(native method) @ java.lang.reflect.method.invoke(method.java:515) @ com.android.internal.os.zygoteinit$methodandargscaller.run(zygoteinit.java:785) @ com.android.internal.os.zygoteinit.main(zygoteinit.java:601) @ dalvik.system.nativestart.main(native method) caused by: android.view.inflateexception: binary xml file line #17: error inflating class android.support.design.widget.navigationview @ android.view.layoutinflater.createview(layoutinflater.java:620) @ android.view.layoutinflater.createviewfromtag(layoutinflater.java:696) @ android.view.layoutinflater.rinflate(layoutinflater.java:755) @ android.view.layoutinflater.inflate(layoutinflater.java:492) @ android.view.layoutinflater.inflate(layoutinflater.java:397) @ android.view.layoutinflater.inflate(layoutinflater.java:353) @ android.support.v7.app.appcompatdelegateimplv9.setcontentview(appcompatdelegateimplv9.java:289) @ android.support.v7.app.appcompatactivity.setcontentview(appcompatactivity.java:139) @ com.vamediabox.vamediaboxapp.activities.mainactivity.oncreate(mainactivity.java:38) @ android.app.activity.performcreate(activity.java:5231) @ android.app.instrumentation.callactivityoncreate(instrumentation.java:1087) @ android.app.activitythread.performlaunchactivity(activitythread.java:2148) @ android.app.activitythread.handlelaunchactivity(activitythread.java:2233) @ android.app.activitythread.access$800(activitythread.java:135) @ android.app.activitythread$h.handlemessage(activitythread.java:1196) @ android.os.handler.dispatchmessage(handler.java:102) @ android.os.looper.loop(looper.java:136) @ android.app.activitythread.main(activitythread.java:5001) @ java.lang.reflect.method.invokenative(native method) @ java.lang.reflect.method.invoke(method.java:515) @ com.android.internal.os.zygoteinit$methodandargscaller.run(zygoteinit.java:785) @ com.android.internal.os.zygoteinit.main(zygoteinit.java:601) @ dalvik.system.nativestart.main(native method) caused by: java.lang.reflect.invocationtargetexception @ java.lang.reflect.constructor.constructnative(native method) @ java.lang.reflect.constructor.newinstance(constructor.java:423) @ android.view.layoutinflater.createview(layoutinflater.java:594) @ android.view.layoutinflater.createviewfromtag(layoutinflater.java:696) @ android.view.layoutinflater.rinflate(layoutinflater.java:755) @ android.view.layoutinflater.inflate(layoutinflater.java:492) @ android.view.layoutinflater.inflate(layoutinflater.java:397) @ android.view.layoutinflater.inflate(layoutinflater.java:353) @ android.support.v7.app.appcompatdelegateimplv9.setcontentview(appcompatdelegateimplv9.java:289) @ android.support.v7.app.appcompatactivity.setcontentview(appcompatactivity.java:139) @ com.vamediabox.vamediaboxapp.activities.mainactivity.oncreate(mainactivity.java:38) @ android.app.activity.performcreate(activity.java:5231) @ android.app.instrumentation.callactivityoncreate(instrumentation.java:1087) @ android.app.activitythread.performlaunchactivity(activitythread.java:2148) @ android.app.activitythread.handlelaunchactivity(activitythread.java:2233) @ android.app.activitythread.access$800(activitythread.java:135) @ android.app.activitythread$h.handlemessage(activitythread.java:1196) @ android.os.handler.dispatchmessage(handler.java:102) @ android.os.looper.loop(looper.java:136) @ android.app.activitythread.main(activitythread.java:5001) @ java.lang.reflect.method.invokenative(native method) @ java.lang.reflect.method.invoke(method.java:515) @ com.android.internal.os.zygoteinit$methodandargscaller.run(zygoteinit.java:785) @ com.android.internal.os.zygoteinit.main(zygoteinit.java:601) @ dalvik.system.nativestart.main(native method) caused by: java.lang.runtimeexception: unexpected end of document @ android.support.v7.view.supportmenuinflater.parsemenu(supportmenuinflater.java:209) @ android.support.v7.view.supportmenuinflater.inflate(supportmenuinflater.java:122) @ android.support.design.widget.navigationview.inflatemenu(navigationview.java:250) @ android.support.design.widget.navigationview.<init>(navigationview.java:174) @ android.support.design.widget.navigationview.<init>(navigationview.java:100) @ java.lang.reflect.constructor.constructnative(native method) @ java.lang.reflect.constructor.newinstance(constructor.java:423) @ android.view.layoutinflater.createview(layoutinflater.java:594) @ android.view.layoutinflater.createviewfromtag(layoutinflater.java:696) @ android.view.layoutinflater.rinflate(layoutinflater.java:755) @ android.view.layoutinflater.inflate(layoutinflater.java:492) @ android.view.layoutinflater.inflate(layoutinflater.java:397) @ android.view.layoutinflater.inflate(layoutinflater.java:353) @ android.support.v7.app.appcompatdelegateimplv9.setcontentview(appcompatdelegateimplv9.java:289) @ android.support.v7.app.appcompatactivity.setcontentview(appcompatactivity.java:139) @ com.vamediabox.vamediaboxapp.activities.mainactivity.oncreate(mainactivity.java:38) @ android.app.activity.performcreate(activity.java:5231) @ android.app.instrumentation.callactivityoncreate(instrumentation.java:1087) @ android.app.activitythread.performlaunchactivity(activitythread.java:2148) @ android.app.activitythread.handlelaunchactivity(activitythread.java:2233) @ android.app.activitythread.access$800(activitythread.java:135) @ android.app.activitythread$h.handlemessage(activitythread.java:1196) @ android.os.handler.dispatchmessage(handler.java:102) @ android.os.looper.loop(looper.java:136) @ android.app.activitythread.main(activitythread.java:5001) @ java.lang.reflect.method.invokenative(native method) @ java.lang.reflect.method.invoke(method.java:515) @ com.android.internal.os.zygoteinit$methodandargscaller.run(zygoteinit.java:785) @ com.android.internal.os.zygoteinit.main(zygoteinit.java:601) @ dalvik.system.nativestart.main(native method)
my activity_main.xml :-
<android.support.v4.widget.drawerlayout 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" android:id="@+id/drawer_layout" android:layout_width="match_parent" android:layout_height="match_parent" android:fitssystemwindows="true" tools:opendrawer="start"> <include layout="@layout/app_bar_navigation_panel" android:layout_width="match_parent" android:layout_height="match_parent" /> <android.support.design.widget.navigationview android:id="@+id/nav_view" android:layout_width="wrap_content" android:layout_height="match_parent" android:layout_gravity="start" android:fitssystemwindows="true" app:headerlayout="@layout/nav_header_navigation_panel" app:itemtextcolor="@color/black" app:menu="@menu/main_drawer" /> </android.support.v4.widget.drawerlayout>
my app_bar_navigation_panel.xml :-
<?xml version="1.0" encoding="utf-8"?> <android.support.design.widget.coordinatorlayout xmlns:android="http://schemas.android.com/apk/res/android" xmlns:tools="http://schemas.android.com/tools" android:layout_width="match_parent" android:layout_height="match_parent" android:fitssystemwindows="true" tools:context="com.vamediabox.vamediaboxapp.activities.mainactivity"> <android.support.design.widget.appbarlayout android:layout_width="match_parent" android:layout_height="wrap_content" android:background="@color/red_button" android:theme="@style/apptheme.appbaroverlay"> <include layout="@layout/toolbar" /> </android.support.design.widget.appbarlayout> <include layout="@layout/content_navigation_panel" /> </android.support.design.widget.coordinatorlayout>
my content_navigation_panel.xml
<?xml version="1.0" encoding="utf-8"?> <linearlayout xmlns:android="http://schemas.android.com/apk/res/android" xmlns:app="http://schemas.android.com/apk/res-auto" android:layout_width="match_parent" android:layout_height="match_parent" app:layout_behavior="@string/appbar_scrolling_view_behavior" android:orientation="vertical"> <framelayout android:id="@+id/your_placeholder" android:layout_width="match_parent" android:layout_height="match_parent" android:background="@color/white" /> </linearlayout>
my nav_header_navigation_panel.xml :-
<?xml version="1.0" encoding="utf-8"?> <relativelayout xmlns:android="http://schemas.android.com/apk/res/android" android:layout_width="match_parent" android:layout_height="@dimen/nav_header_height" android:layout_gravity="center" android:gravity="center" android:orientation="vertical" android:paddingbottom="@dimen/activity_vertical_margin" android:paddingleft="@dimen/activity_horizontal_margin" android:paddingright="@dimen/activity_horizontal_margin" android:paddingtop="@dimen/activity_vertical_margin" android:background="@drawable/background1" android:theme="@style/themeoverlay.appcompat.dark"> <imageview android:layout_width="wrap_content" android:layout_height="wrap_content" android:src="@drawable/logo" android:id="@+id/iv1" android:scaletype="fitcenter"/> <textview android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_below="@+id/iv1" android:layout_margintop="15dp" android:textsize="15sp" android:text="www.vamediabox.com" android:textcolor="@color/white"/> </relativelayout>
my toobar.xml
<android.support.v7.widget.toolbar xmlns:android="http://schemas.android.com/apk/res/android" xmlns:app="http://schemas.android.com/apk/res-auto" android:id="@+id/toolbar" android:background="@drawable/background1" android:layout_width="match_parent" android:layout_height="?attr/actionbarsize" app:popuptheme="@style/themeoverlay.appcompat.light" app:theme="@style/themeoverlay.appcompat.dark.actionbar" />
my main_drawer.xml :-
<menu xmlns:android="http://schemas.android.com/apk/res/android" xmlns:anroid="http://schemas.android.com/apk/res-auto"> <group android:checkablebehavior="single"> <item android:id="@+id/nav_home" android:icon="@drawable/ic_home_black_24dp" android:title="home" /> <item android:id="@+id/nav_about" android:icon="@drawable/ic_info_black_24dp" android:title="about us" /> <item android:id="@+id/nav_services" android:icon="@drawable/ic_settings_black_24dp" android:title="services" /> <item android:id="@+id/nav_portfolio" android:icon="@drawable/ic_card_travel_black_24dp" android:title="portfolio" /> <item android:id="@+id/nav_contact" android:icon="@drawable/ic_contact_mail_black_24dp" android:title="contact" /> </group> <menu> <item android:id="@+id/nav_exit" android:icon="@drawable/ic_exit_to_app_black_24dp" android:title="exit" /> </menu> </menu>
my home_fragment.xml
<relativelayout xmlns:android="http://schemas.android.com/apk/res/android" xmlns:tools="http://schemas.android.com/tools" android:layout_width="match_parent" android:layout_height="match_parent" android:background="@drawable/background1" android:layout_margintop="15dp" tools:context="com.vamediabox.vamediaboxapp.activities.mainactivity"> <linearlayout android:layout_width="match_parent" android:layout_height="wrap_content" android:id="@+id/ly_homeimage"> <imageview android:layout_width="match_parent" android:layout_height="250dp" android:src="@drawable/socialmedia" android:scaletype="fitxy"/> </linearlayout> <linearlayout android:layout_width="match_parent" android:layout_height="wrap_content" android:layout_below="@+id/ly_homeimage" android:layout_margin="10dp"> <scrollview android:layout_width="match_parent" android:layout_height="wrap_content"> <textview android:layout_width="wrap_content" android:layout_height="wrap_content" android:textsize="25sp" android:textstyle="bold" android:textcolor="@color/aluminum" android:text="@string/activity_home" /> </scrollview> </linearlayout> </relativelayout>
my main_activity.java
public class mainactivity extends appcompatactivity implements navigationview.onnavigationitemselectedlistener { fragment fragment; fragmentmanager fragmentmanager; toolbar toolbar; private bundle bundle; @override protected void oncreate(bundle savedinstancestate) { super.oncreate(savedinstancestate); setcontentview(r.layout.activity_main); toolbar = (toolbar) findviewbyid(r.id.toolbar); setsupportactionbar(toolbar); final drawerlayout drawer = (drawerlayout) findviewbyid(r.id.drawer_layout); actionbardrawertoggle toggle = new actionbardrawertoggle(this, drawer, toolbar, r.string.navigation_drawer_open, r.string.navigation_drawer_close); assert drawer != null; drawer.setdrawerlistener(toggle); drawer.setscrimcolor(color.transparent); toggle.syncstate(); toggle.settoolbarnavigationclicklistener(new view.onclicklistener() { @override public void onclick(view view) { if (drawer.isdrawervisible(gravitycompat.start)) { drawer.closedrawer(gravitycompat.start); } else { drawer.opendrawer(gravitycompat.start); } } }); navigationview navigationview = (navigationview) findviewbyid(r.id.nav_view); navigationview.setnavigationitemselectedlistener(this); bundle = getintent().getextras(); fragment = new homefragment(); getsupportactionbar().settitle("vamedia box"); setfragment(); } @override protected void onstop() { super.onstop(); } public void setfragment() { fragmentmanager manager = getsupportfragmentmanager(); fragmenttransaction transaction = manager.begintransaction(); transaction.replace(r.id.your_placeholder, fragment).addtobackstack(null); transaction.commit(); } private void showmessagedialog(final boolean exit) { //exit dialog final android.app.dialog popuplayout = new android.app.dialog(mainactivity.this); popuplayout.requestwindowfeature(window.feature_no_title); popuplayout.setcontentview(r.layout.exitdialog); popuplayout.getwindow().setbackgrounddrawable(new colordrawable(color.transparent)); button btnyes = (button) popuplayout.findviewbyid(r.id.btnyes); button btnno = (button) popuplayout.findviewbyid(r.id.btnno); textview tittle = (textview) popuplayout.findviewbyid(r.id.txtdialogtitle); tittle.settext(""); textview msg = (textview) popuplayout.findviewbyid(r.id.txtdialogmsg); if (!exit) msg.settext("do want exit application?"); else msg.settext("do want exit application?"); display display = ((windowmanager) getsystemservice(context.window_service)).getdefaultdisplay(); int width = display.getwidth(); popuplayout.show(); windowmanager.layoutparams lp = new windowmanager.layoutparams(); lp.copyfrom(popuplayout.getwindow().getattributes()); lp.width = (int) (width - (width * 0.20)); lp.height = windowmanager.layoutparams.wrap_content; popuplayout.getwindow().setattributes(lp); btnyes.setonclicklistener(new view.onclicklistener() { @override public void onclick(view v) { popuplayout.cancel(); if (!exit) { finish(); } else { movetasktoback(true); finish(); } } }); btnno.setonclicklistener(new view.onclicklistener() { @override public void onclick(view v) { popuplayout.cancel(); } }); } @override public void onbackpressed() { drawerlayout drawer = (drawerlayout) findviewbyid(r.id.drawer_layout); if (drawer.isdraweropen(gravitycompat.start)) { drawer.closedrawer(gravitycompat.start); } else { showmessagedialog(true); } } @suppresswarnings("statementwithemptybody") @override public boolean onnavigationitemselected(@nonnull menuitem item) { string title = ""; switch (item.getitemid()) { case r.id.nav_home: { fragment = new homefragment(); title = "vamedia box "; break; } case r.id.nav_exit: { title = "vamedia box"; showmessagedialog(true); } } getsupportactionbar().settitle(title); drawerlayout drawer = (drawerlayout) findviewbyid(r.id.drawer_layout); drawer.closedrawer(gravitycompat.start); setfragment(); return true; } }
my homefragment.java
public class homefragment extends fragment { private static final string arg_param1 = "param1"; private static final string arg_param2 = "param2"; private string mparam1; private string mparam2; private onfragmentinteractionlistener mlistener; public homefragment() { } public static homefragment newinstance(string param1, string param2) { homefragment fragment = new homefragment(); bundle args = new bundle(); args.putstring(arg_param1, param1); args.putstring(arg_param2, param2); fragment.setarguments(args); return fragment; } @override public void oncreate(bundle savedinstancestate) { super.oncreate(savedinstancestate); if (getarguments() != null) { mparam1 = getarguments().getstring(arg_param1); mparam2 = getarguments().getstring(arg_param2); } } @override public view oncreateview(layoutinflater inflater, viewgroup container,bundle savedinstancestate) { // inflate layout fragment return inflater.inflate(r.layout.fragment_home, container, false); } // todo: rename method, update argument , hook method ui event public void onbuttonpressed(uri uri) { if (mlistener != null) { mlistener.onfragmentinteraction(uri); } } @override public void onattach(context context) { super.onattach(context); } @override public void ondetach() { super.ondetach(); mlistener = null; } public interface onfragmentinteractionlistener { // todo: update argument type , name void onfragmentinteraction(uri uri); } }
caused by: java.lang.runtimeexception: unexpected end of document @ android.support.v7.view.supportmenuinflater.parsemenu(supportmenuinflater.java:209)
as per official doc
<menu> defines menu, container menu items. <menu> element must root node file , can hold 1 or more <item> , <group> elements.
change main_drawer.xml work
<menu xmlns:android="http://schemas.android.com/apk/res/android" xmlns:anroid="http://schemas.android.com/apk/res-auto"> <group android:checkablebehavior="single"> <item android:id="@+id/nav_home" android:icon="@drawable/ic_home_black_24dp" android:title="home"/> <item android:id="@+id/nav_about" android:icon="@drawable/ic_info_black_24dp" android:title="about us"/> <item android:id="@+id/nav_services" android:icon="@drawable/ic_settings_black_24dp" android:title="services"/> <item android:id="@+id/nav_portfolio" android:icon="@drawable/ic_card_travel_black_24dp" android:title="portfolio"/> <item android:id="@+id/nav_contact" android:icon="@drawable/ic_contact_mail_black_24dp" android:title="contact"/> </group> <item android:id="@+id/nav_exit" android:icon="@drawable/ic_exit_to_app_black_24dp" android:title="exit"/> </menu>
Comments
Post a Comment