Unfortunately,NavigationBar has stopped in android studio emulator -
i have done coding in android studio when running app in android studio emulator it's not working. here code:- **mainactivity.java** package com.example.arpi.navigationbar; import android.app.activity; import android.os.bundle; import android.support.v4.app.fragment; import android.support.v4.app.fragmentmanager; import android.support.v4.widget.drawerlayout; import android.view.layoutinflater; import android.view.menu; import android.view.menuitem; import android.view.view; import android.view.viewgroup; import android.app.actionbar; public class mainactivity extends activity implements navigationdrawerfragment.navigationdrawercallbacks { /** * fragment managing behaviors, interactions , presentation of navigation drawer. */ private navigationdrawerfragment mnavigationdrawerfragment; /** * used store last screen title. use in {@link #restoreactionbar()}. */ private charsequence mtitle; @override protected void oncreate(bundle savedinstancestate) { super.oncreate(savedinstancestate); setcontentview(r.layout.activity_main); mnavigationdrawerfragment = (navigationdrawerfragment) getsupportfragmentmanager().findfragmentbyid(r.id.navigation_drawer); mtitle = gettitle(); // set drawer. mnavigationdrawerfragment.setup( r.id.navigation_drawer, (drawerlayout) findviewbyid(r.id.drawer_layout)); } @override public void onnavigationdraweritemselected(int position) { fragment objfragment=null; switch (position){ case 0: objfragment=new menu1_fragment(); break; case 1: objfragment=new menu2_fragment(); break; case 2: objfragment=new menu3_fragment(); break; } // update main content replacing fragments fragmentmanager fragmentmanager = getsupportfragmentmanager(); fragmentmanager.begintransaction() .replace(r.id.container, objfragment) .commit(); } private fragmentmanager getsupportfragmentmanager() { return null; }; public void onsectionattached(int number) { switch (number) { case 1: mtitle = getstring(r.string.title_section1); break; case 2: mtitle = getstring(r.string.title_section2); break; case 3: mtitle = getstring(r.string.title_section3); break; } } public void restoreactionbar() { actionbar actionbar = getsupportactionbar(); actionbar.setnavigationmode(actionbar.navigation_mode_standard); actionbar.setdisplayshowtitleenabled(true); actionbar.settitle(mtitle); } private actionbar getsupportactionbar() { return null; } @override public boolean oncreateoptionsmenu(menu menu) { if (!mnavigationdrawerfragment.isdraweropen()) { // show items in action bar relevant screen // if drawer not showing. otherwise, let drawer // decide show in action bar. getmenuinflater().inflate(r.menu.main, menu); restoreactionbar(); return true; } return super.oncreateoptionsmenu(menu); } @override public boolean onoptionsitemselected(menuitem item) { // handle action bar item clicks here. action bar // automatically handle clicks on home/up button, long // specify parent activity in androidmanifest.xml. int id = item.getitemid(); //noinspection simplifiableifstatement if (id == r.id.action_settings) { return true; } return super.onoptionsitemselected(item); } /** * placeholder fragment containing simple view. */ public static class placeholderfragment extends fragment { /** * fragment argument representing section number * fragment. */ private static final string arg_section_number = "section_number"; /** * returns new instance of fragment given section * number. */ public static placeholderfragment newinstance(int sectionnumber) { placeholderfragment fragment = new placeholderfragment(); bundle args = new bundle(); args.putint(arg_section_number, sectionnumber); fragment.setarguments(args); return fragment; } public placeholderfragment() { } @override public view oncreateview(layoutinflater inflater, viewgroup container, bundle savedinstancestate) { view rootview = inflater.inflate(r.layout.fragment_main, container, false); return rootview; } @override public void onattach(activity activity) { super.onattach(activity); ((mainactivity) activity).onsectionattached( getarguments().getint(arg_section_number)); } } } have made 3 menu navigationbar.i not able see output app not able run emulator.please provide solution problem. these different menu navigation bar:- ***menu1_fragment.java*** package com.example.arpi.navigationbar; import android.support.v4.app.fragment; import android.os.bundle; import android.support.annotation.nullable; import android.view.layoutinflater; import android.view.view; import android.view.viewgroup; /** * created user on 26-06-2015. */ public class menu1_fragment extends fragment { view rootview; @nullable @override public view oncreateview(layoutinflater inflater,viewgroup container,bundle savedinstancestate){ rootview=inflater.inflate(r.layout.menu1_layout,container,false); return rootview; } } ***navigationdrawerfragment.java*** package com.example.arpi.navigationbar; import android.support.v7.app.actionbaractivity; import android.app.activity; import android.support.v7.app.actionbar; import android.support.v4.app.fragment; import android.support.v4.app.actionbardrawertoggle; import android.support.v4.view.gravitycompat; import android.support.v4.widget.drawerlayout; import android.content.sharedpreferences; import android.content.res.configuration; import android.os.bundle; import android.preference.preferencemanager; import android.view.layoutinflater; import android.view.menu; import android.view.menuinflater; import android.view.menuitem; import android.view.view; import android.view.viewgroup; import android.widget.adapterview; import android.widget.arrayadapter; import android.widget.listview; import android.widget.toast; /** * fragment used managing interactions , presentation of navigation drawer. * see <a href="https://developer.android.com/design/patterns/navigation-drawer.html#interaction"> * design guidelines</a> complete explanation of behaviors implemented here. */ public class navigationdrawerfragment extends fragment { private static final string state_selected_position = "selected_navigation_drawer_position"; private static final string pref_user_learned_drawer = "navigation_drawer_learned"; private navigationdrawercallbacks mcallbacks; private actionbardrawertoggle mdrawertoggle; private drawerlayout mdrawerlayout; private listview mdrawerlistview; private view mfragmentcontainerview; private int mcurrentselectedposition = 0; private boolean mfromsavedinstancestate; private boolean muserlearneddrawer; public navigationdrawerfragment() { } @override public void oncreate(bundle savedinstancestate) { super.oncreate(savedinstancestate); // read in flag indicating whether or not user has demonstrated awareness of // drawer. see pref_user_learned_drawer details. sharedpreferences sp = preferencemanager.getdefaultsharedpreferences(getactivity()); muserlearneddrawer = sp.getboolean(pref_user_learned_drawer, false); if (savedinstancestate != null) { mcurrentselectedposition = savedinstancestate.getint(state_selected_position); mfromsavedinstancestate = true; } // select either default item (0) or last selected item. selectitem(mcurrentselectedposition); } @override public void onactivitycreated(bundle savedinstancestate) { super.onactivitycreated(savedinstancestate); // indicate fragment influence set of actions in action bar. sethasoptionsmenu(true); } @override public view oncreateview(layoutinflater inflater, viewgroup container, bundle savedinstancestate) { mdrawerlistview = (listview) inflater.inflate( r.layout.fragment_navigation_drawer, container, false); mdrawerlistview.setonitemclicklistener(new adapterview.onitemclicklistener() { @override public void onitemclick(adapterview<?> parent, view view, int position, long id) { selectitem(position); } }); mdrawerlistview.setadapter(new arrayadapter<string>( getactionbar().getthemedcontext(), android.r.layout.simple_list_item_activated_1, android.r.id.text1, new string[]{ getstring(r.string.title_section1), getstring(r.string.title_section2), getstring(r.string.title_section3), })); mdrawerlistview.setitemchecked(mcurrentselectedposition, true); return mdrawerlistview; } public boolean isdraweropen() { return mdrawerlayout != null && mdrawerlayout.isdraweropen(mfragmentcontainerview); } /** * users of fragment must call method set navigation drawer interactions. * * @param fragmentid android:id of fragment in activity's layout. * @param drawerlayout drawerlayout containing fragment's ui. */ public void setup(int fragmentid, drawerlayout drawerlayout) { mfragmentcontainerview = getactivity().findviewbyid(fragmentid); mdrawerlayout = drawerlayout; // set custom shadow overlays main content when drawer opens mdrawerlayout.setdrawershadow(r.drawable.drawer_shadow, gravitycompat.start); // set drawer's list view items , click listener actionbar actionbar = getactionbar(); actionbar.setdisplayhomeasupenabled(true); actionbar.sethomebuttonenabled(true); // actionbardrawertoggle ties the proper interactions // between navigation drawer , action bar app icon. mdrawertoggle = new actionbardrawertoggle( getactivity(), /* host activity */ mdrawerlayout, /* drawerlayout object */ r.drawable.ic_drawer, /* nav drawer image replace 'up' caret */ r.string.navigation_drawer_open, /* "open drawer" description accessibility */ r.string.navigation_drawer_close /* "close drawer" description accessibility */ ) { @override public void ondrawerclosed(view drawerview) { super.ondrawerclosed(drawerview); if (!isadded()) { return; } getactivity().supportinvalidateoptionsmenu(); // calls onprepareoptionsmenu() } @override public void ondraweropened(view drawerview) { super.ondraweropened(drawerview); if (!isadded()) { return; } if (!muserlearneddrawer) { // user manually opened drawer; store flag prevent auto-showing // navigation drawer automatically in future. muserlearneddrawer = true; sharedpreferences sp = preferencemanager .getdefaultsharedpreferences(getactivity()); sp.edit().putboolean(pref_user_learned_drawer, true).apply(); } getactivity().supportinvalidateoptionsmenu(); // calls onprepareoptionsmenu() } }; // if user hasn't 'learned' drawer, open introduce them drawer, // per navigation drawer design guidelines. if (!muserlearneddrawer && !mfromsavedinstancestate) { mdrawerlayout.opendrawer(mfragmentcontainerview); } // defer code dependent on restoration of previous instance state. mdrawerlayout.post(new runnable() { @override public void run() { mdrawertoggle.syncstate(); } }); mdrawerlayout.setdrawerlistener(mdrawertoggle); } private void selectitem(int position) { mcurrentselectedposition = position; if (mdrawerlistview != null) { mdrawerlistview.setitemchecked(position, true); } if (mdrawerlayout != null) { mdrawerlayout.closedrawer(mfragmentcontainerview); } if (mcallbacks != null) { mcallbacks.onnavigationdraweritemselected(position); } } @override public void onattach(activity activity) { super.onattach(activity); try { mcallbacks = (navigationdrawercallbacks) activity; } catch (classcastexception e) { throw new classcastexception("activity must implement navigationdrawercallbacks."); } } @override public void ondetach() { super.ondetach(); mcallbacks = null; } @override public void onsaveinstancestate(bundle outstate) { super.onsaveinstancestate(outstate); outstate.putint(state_selected_position, mcurrentselectedposition); } @override public void onconfigurationchanged(configuration newconfig) { super.onconfigurationchanged(newconfig); // forward new configuration drawer toggle component. mdrawertoggle.onconfigurationchanged(newconfig); } @override public void oncreateoptionsmenu(menu menu, menuinflater inflater) { // if drawer open, show global app actions in action bar. see // showglobalcontextactionbar, controls top-left area of action bar. if (mdrawerlayout != null && isdraweropen()) { inflater.inflate(r.menu.global, menu); showglobalcontextactionbar(); } super.oncreateoptionsmenu(menu, inflater); } @override public boolean onoptionsitemselected(menuitem item) { if (mdrawertoggle.onoptionsitemselected(item)) { return true; } if (item.getitemid() == r.id.action_example) { toast.maketext(getactivity(), "example action.", toast.length_short).show(); return true; } return super.onoptionsitemselected(item); } /** * per navigation drawer design guidelines, updates action bar show global app * 'context', rather what's in current screen. */ private void showglobalcontextactionbar() { actionbar actionbar = getactionbar(); actionbar.setdisplayshowtitleenabled(true); actionbar.setnavigationmode(actionbar.navigation_mode_standard); actionbar.settitle(r.string.app_name); } private actionbar getactionbar() { return ((actionbaractivity) getactivity()).getsupportactionbar(); } /** * callbacks interface activities using fragment must implement. */ public static interface navigationdrawercallbacks { /** * called when item in navigation drawer selected. */ void onnavigationdraweritemselected(int position); } }
this logcat.there errors due ehich ai not able see output. logcat error:- 06-27 14:59:09.667 2791-2791/? d/dalvikvm﹕ not late-enabling checkjni (already on) 06-27 14:59:12.277 2791-2791/com.example.arpi.navigationbar e/trace﹕ error opening trace file: no such file or directory (2) 06-27 14:59:19.408 2791-2791/com.example.arpi.navigationbar d/androidruntime﹕ shutting down vm 06-27 14:59:19.408 2791-2791/com.example.arpi.navigationbar w/dalvikvm﹕ threadid=1: thread exiting uncaught exception (group=0x40a71930) 06-27 14:59:19.508 2791-2791/com.example.arpi.navigationbar e/androidruntime﹕ fatal exception: main java.lang.runtimeexception: unable start activity componentinfo{com.example.arpi.navigationbar/com.example.arpi.navigationbar.mainactivity}: android.view.inflateexception: binary xml file line #19: error inflating class fragment @ android.app.activitythread.performlaunchactivity(activitythread.java:2180) @ android.app.activitythread.handlelaunchactivity(activitythread.java:2230) @ android.app.activitythread.access$600(activitythread.java:141) @ android.app.activitythread$h.handlemessage(activitythread.java:1234) @ android.os.handler.dispatchmessage(handler.java:99) @ android.os.looper.loop(looper.java:137) @ android.app.activitythread.main(activitythread.java:5041) @ java.lang.reflect.method.invokenative(native method) @ java.lang.reflect.method.invoke(method.java:511) @ com.android.internal.os.zygoteinit$methodandargscaller.run(zygoteinit.java:793) @ com.android.internal.os.zygoteinit.main(zygoteinit.java:560) @ dalvik.system.nativestart.main(native method) caused by: android.view.inflateexception: binary xml file line #19: error inflating class fragment @ android.view.layoutinflater.createviewfromtag(layoutinflater.java:704) @ android.view.layoutinflater.rinflate(layoutinflater.java:746) @ android.view.layoutinflater.inflate(layoutinflater.java:489) @ android.view.layoutinflater.inflate(layoutinflater.java:396) @ android.view.layoutinflater.inflate(layoutinflater.java:352) @ com.android.internal.policy.impl.phonewindow.setcontentview(phonewindow.java:270) @ android.app.activity.setcontentview(activity.java:1881) @ com.example.arpi.navigationbar.mainactivity.oncreate(mainactivity.java:33) @ android.app.activity.performcreate(activity.java:5104) @ android.app.instrumentation.callactivityoncreate(instrumentation.java:1080) @ android.app.activitythread.performlaunchactivity(activitythread.java:2144) at android.app.activitythread.handlelaunchactivity(activitythread.java:2230) at android.app.activitythread.access$600(activitythread.java:141) at android.app.activitythread$h.handlemessage(activitythread.java:1234) at android.os.handler.dispatchmessage(handler.java:99) at android.os.looper.loop(looper.java:137) at android.app.activitythread.main(activitythread.java:5041) 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:793) at com.android.internal.os.zygoteinit.main(zygoteinit.java:560) at dalvik.system.nativestart.main(native method) caused by: android.app.fragment$instantiationexception: trying instantiate class com.example.arpi.navigationbar.navigationdrawerfragment not fragment @ android.app.fragment.instantiate(fragment.java:584) @ android.app.fragment.instantiate(fragment.java:560) @ android.app.activity.oncreateview(activity.java:4709) @ android.view.layoutinflater.createviewfromtag(layoutinflater.java:680) at android.view.layoutinflater.rinflate(layoutinflater.java:746) at android.view.layoutinflater.inflate(layoutinflater.java:489) at android.view.layoutinflater.inflate(layoutinflater.java:396) at android.view.layoutinflater.inflate(layoutinflater.java:352) at com.android.internal.policy.impl.phonewindow.setcontentview(phonewindow.java:270) at android.app.activity.setcontentview(activity.java:1881) at com.example.arpi.navigationbar.mainactivity.oncreate(mainactivity.java:33) at android.app.activity.performcreate(activity.java:5104) at android.app.instrumentation.callactivityoncreate(instrumentation.java:1080) at android.app.activitythread.performlaunchactivity(activitythread.java:2144) at android.app.activitythread.handlelaunchactivity(activitythread.java:2230) at android.app.activitythread.access$600(activitythread.java:141) at android.app.activitythread$h.handlemessage(activitythread.java:1234) at android.os.handler.dispatchmessage(handler.java:99) at android.os.looper.loop(looper.java:137) at android.app.activitythread.main(activitythread.java:5041) 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:793) at com.android.internal.os.zygoteinit.main(zygoteinit.java:560) at dalvik.system.nativestart.main(native method) caused by: java.lang.classcastexception at android.app.fragment.instantiate(fragment.java:584) at android.app.fragment.instantiate(fragment.java:560) at android.app.activity.oncreateview(activity.java:4709) at android.view.layoutinflater.createviewfromtag(layoutinflater.java:680) at android.view.layoutinflater.rinflate(layoutinflater.java:746) at android.view.layoutinflater.inflate(layoutinflater.java:489) at android.view.layoutinflater.inflate(layoutinflater.java:396) at android.view.layoutinflater.inflate(layoutinflater.java:352) at com.android.internal.policy.impl.phonewindow.setcontentview(phonewindow.java:270) at android.app.activity.setcontentview(activity.java:1881) at com.example.arpi.navigationbar.mainactivity.oncreate(mainactivity.java:33) at android.app.activity.performcreate(activity.java:5104) at android.app.instrumentation.callactivityoncreate(instrumentation.java:1080) at android.app.activitythread.performlaunchactivity(activitythread.java:2144) at android.app.activitythread.handlelaunchactivity(activitythread.java:2230) at android.app.activitythread.access$600(activitythread.java:141) at android.app.activitythread$h.handlemessage(activitythread.java:1234) at android.os.handler.dispatchmessage(handler.java:99) at android.os.looper.loop(looper.java:137) at android.app.activitythread.main(activitythread.java:5041) 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:793) at com.android.internal.os.zygoteinit.main(zygoteinit.java:560) at dalvik.system.nativestart.main(native method)
check line in logcat unable start activity componentinfo{com.example.arpi.navigationbar/com.example.arpi.navigationbar.mainactivity}: android.view.inflateexception: binary xml file line #19: error inflating class fragment @ android.app.activitythread.performlaunchactivity
shows android system not able parse layout xml due caused by: java.lang.classcastexception
.
check
error-inflating-class-fragment
inflateexception-binary-xml-file-error-inflating-class-fragment
Comments
Post a Comment