Android.view.InflateException: Binary XML file line #1: Error inflating class menu -
i have been following udacity's "developing android apps" course , have stumbled upon problem. in tutorials, asked create xml file called forecastfragment.xml
, below:
<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.android.sunshine.app.mainactivity" android:layout_width="match_parent" android:layout_height="match_parent"> <item android:id="@+id/action_refresh" android:title="@string/action_refresh" app:showasaction="never" /> </menu>
and told inflate fragment class called forecastfragment.java
, process happens on line:
view rootview = inflater.inflate(r.layout.forecastfragment, container, false);
my problem that, when try running app, error:
05-24 21:40:02.848 11882-11882/com.example.android.sunshine.app e/androidruntime: fatal exception: main process: com.example.android.sunshine.app, pid: 11882 java.lang.runtimeexception: unable start activity componentinfo{com.example.android.sunshine.app/com.example.android.sunshine.app.mainactivity}: android.view.inflateexception: binary xml file line #1: error inflating class menu @ android.app.activitythread.performlaunchactivity(activitythread.java:2379) @ android.app.activitythread.handlelaunchactivity(activitythread.java:2431) @ android.app.activitythread.access$800(activitythread.java:151) @ android.app.activitythread$h.handlemessage(activitythread.java:1342) @ android.os.handler.dispatchmessage(handler.java:110) @ android.os.looper.loop(looper.java:193) @ android.app.activitythread.main(activitythread.java:5335) @ java.lang.reflect.method.invokenative(native method) @ java.lang.reflect.method.invoke(method.java:515) @ com.android.internal.os.zygoteinit$methodandargscaller.run(zygoteinit.java:828) @ com.android.internal.os.zygoteinit.main(zygoteinit.java:644) @ dalvik.system.nativestart.main(native method) caused by: android.view.inflateexception: binary xml file line #1: error inflating class menu @ android.view.layoutinflater.createviewfromtag(layoutinflater.java:707) @ android.view.layoutinflater.inflate(layoutinflater.java:469) @ android.view.layoutinflater.inflate(layoutinflater.java:397) @ com.example.android.sunshine.app.forecastfragment.oncreateview(forecastfragment.java:34) @ android.support.v4.app.fragment.performcreateview(fragment.java:1974) @ android.support.v4.app.fragmentmanagerimpl.movetostate(fragmentmanager.java:1036) @ android.support.v4.app.fragmentmanagerimpl.movetostate(fragmentmanager.java:1230) @ android.support.v4.app.fragmentmanagerimpl.addfragment(fragmentmanager.java:1332) @ android.support.v4.app.fragmentmanagerimpl.oncreateview(fragmentmanager.java:2288) @ android.support.v4.app.fragmentcontroller.oncreateview(fragmentcontroller.java:120) @ android.support.v4.app.fragmentactivity.dispatchfragmentsoncreateview(fragmentactivity.java:356) @ android.support.v4.app.basefragmentactivityhoneycomb.oncreateview(basefragmentactivityhoneycomb.java:31) @ android.support.v4.app.fragmentactivity.oncreateview(fragmentactivity.java:79) @ android.view.layoutinflater.createviewfromtag(layoutinflater.java:689) @ android.view.layoutinflater.parseinclude(layoutinflater.java:816) @ android.view.layoutinflater.rinflate(layoutinflater.java:745) @ 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.appcompatdelegateimplv7.setcontentview(appcompatdelegateimplv7.java:280) @ android.support.v7.app.appcompatactivity.setcontentview(appcompatactivity.java:140) @ com.example.android.sunshine.app.mainactivity.oncreate(mainactivity.java:17) @ android.app.activity.performcreate(activity.java:5343) @ android.app.instrumentation.callactivityoncreate(instrumentation.java:1088) @ android.app.activitythread.performlaunchactivity(activitythread.java:2331) @ android.app.activitythread.handlelaunchactivity(activitythread.java:2431) @ android.app.activitythread.access$800(activitythread.java:151) @ android.app.activitythread$h.handlemessage(activitythread.java:1342) @ android.os.handler.dispatchmessage(handler.java:110) @ android.os.looper.loop(looper.java:193) @ android.app.activitythread.main(activitythread.java:5335) @ java.lang.reflect.method.invokenative(native method) @ java.lang.reflect.method.invoke(method.java:515) @ com.android.internal.os.zygoteinit$methodandargscaller.run(zygoteinit.java:828) @ com.android.internal.os.zygoteinit.main(zygoteinit.java:644) @ dalvik.system.nativestart.main(native method) caused by: java.lang.classnotfoundexception: didn't find class "android.view.menu" on path: dexpathlist[[zip file "/data/app/com.example.android.sunshine.app-2.apk"],nativelibrarydirectories=[/data/app-lib/com.example.android.sunshine.app-2, /vendor/lib, /system/lib]] @ dalvik.system.basedexclassloader.findclass(basedexclassloader.java:56) @ java.lang.classloader.loadclass(classloader.java:497) @ java.lang.classloader.loadclass(classloader.java:457) @ android.view.layoutinflater.createview(layoutinflater.java:559) @ android.view.layoutinflater.oncreateview(layoutinflater.java:652) @ com.android.internal.policy.impl.phonelayoutinflater.oncreateview(phonelayoutinflater.java:66) @ android.view.layoutinflater.oncreateview(layoutinflater.java:669) @ android.view.layoutinflater.createviewfromtag(layoutinflater.java:694) @ android.view.layoutinflater.inflate(layoutinflater.java:469) @ android.view.layoutinflater.inflate(layoutinflater.java:397) @ com.example.android.sunshine.app.forecastfragment.oncreateview(forecastfragment.java:34) @ android.support.v4.app.fragment.performcreateview(fragment.java:1974) @ android.support.v4.app.fragmentmanagerimpl.movetostate(fragmentmanager.java:1036) @ android.support.v4.app.fragmentmanagerimpl.movetostate(fragmentmanager.java:1230) @ android.support.v4.app.fragmentmanagerimpl.addfragment(fragmentmanager.java:1332) @ android.support.v4.app.fragmentmanagerimpl.oncreateview(fragmentmanager.java:2288) @ android.support.v4.app.fragmentcontroller.oncreateview(fragmentcontroller.java:120) @ android.support.v4.app.fragmentactivity.dispatchfragmentsoncreateview(fragmentactivity.java:356) @ android.support.v4.app.basefragmentactivityhoneycomb.oncreateview(basefragmentactivityhoneycomb.java:31) @ android.support.v4.app.fragmentactivity.oncreateview(fragmentactivity.java:79) @ android.view.layoutinflater.createviewfromtag(layoutinflater.java:689) @ android.view.layoutinflater.parseinclude(layoutinflater.java:816) @ android.view.layoutinflater.rinflate(layoutinflater.java:745) @ 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.appcompatdelegateimplv7.setcontentview(appcompatdelegateimplv7.java:280) @ android.support.v7.app.appcompatactivity.setcontentview(appcompatactivity.java:140) @ com.example.android.sunshine.app.mainactivity.oncreate(mainactivity.java:17) @ android.app.activity.performcreate(activity.java:5343) @ android.app.instrumentation.callactivityoncreate(instrumentation.java:1088) @ android.app.activitythread.performlaunchactivity(activitythread.java:2331) @ android.app.activitythread.handlelaunchactivity(activitythread.java:2431) @ android.app.activitythread.access$800(activitythread.java:151) @ android.app.activitythread$h.handlemessage(activitythread.java:1342) @ android.os.handler.dispatchmessage(handler.java:110) @ android.os.looper.loop(looper.java:193) @ android.app.activitythread.main(activitythread.java:5335) @ java.lang.reflect.method.invokenative(native method) @ java.lang.reflect.method.invoke(method.java:515)
from line:
java.lang.runtimeexception: unable start activity componentinfo{com.example.android.sunshine.app/com.example.android.sunshine.app.mainactivity}: android.view.inflateexception: binary xml file line #1: error inflating class menu
i guessing problem within xml file, don't understand wrong, no errors thrown. i'm thinking that, since new @ this, may simple error. know why? thank in advance
the above mentioned xml file menu file. adding menu items action bar.
so cannot inflated fragment layout file. first of need create layout file fragment.
then need inflate forecastfragment.xml menu action bar.
follow below steps:
1.create normal layout xml file sample.xml inside /res/layout/ , inflate fragment writing below line of code in oncreateview:
view rootview = inflater.inflate(r.layout.sample, container, false);
2. override function: oncreateoptionsmenu(menu menu) , inside inflate forecastfragment.xml this:
getmenuinflater().inflate(r.menu.forecastfragment, menu); return true;
also add below line of code in fragment's oncreate method:
sethasoptionsmenu(true);
one more thing: place forecastfragment.xml inside /res/menu folder.
Comments
Post a Comment