Getting resource not found exception in android app -
i trying build app in aosp, development kit has hdpi density, have double verified following code snippet:
switch (getresources().getdisplaymetrics().densitydpi) { case displaymetrics.density_low: log.d(tag, "\n\n\n\n ldpi \n\n\n\n"); break; case displaymetrics.density_medium: log.d(tag, "\n\n\n\n mdpi \n\n\n\n"); break; case displaymetrics.density_high: log.d(tag, "\n\n\n\n hdpi \n\n\n\n"); // ... break; case displaymetrics.density_xhigh: log.d(tag, "\n\n\n\n xdpi \n\n\n\n"); // ... break; }
when build application in android file system,and if run it, getting following error:
e/androidruntime( 825): java.lang.runtimeexception: unable start activity componentinfo{com.example/com.example.mainactivity}: android.view.inflateexception: binary xml file line #11: error inflating class android.widget.button e/androidruntime( 825): @ android.app.activitythread.performlaunchactivity(activitythread.java:1956) e/androidruntime( 825): @ android.app.activitythread.handlelaunchactivity(activitythread.java:1981) e/androidruntime( 825): @ android.app.activitythread.access$600(activitythread.java:123) e/androidruntime( 825): @ android.app.activitythread$h.handlemessage(activitythread.java:1147) e/androidruntime( 825): @ android.os.handler.dispatchmessage(handler.java:99) e/androidruntime( 825): @ android.os.looper.loop(looper.java:137) e/androidruntime( 825): @ android.app.activitythread.main(activitythread.java:4424) e/androidruntime( 825): @ java.lang.reflect.method.invokenative(native method) e/androidruntime( 825): @ java.lang.reflect.method.invoke(method.java:511) e/androidruntime( 825): @ com.android.internal.os.zygoteinit$methodandargscaller.run(zygoteinit.java:784) e/androidruntime( 825): @ com.android.internal.os.zygoteinit.main(zygoteinit.java:551) e/androidruntime( 825): @ dalvik.system.nativestart.main(native method) e/androidruntime( 825): caused by: android.view.inflateexception: binary xml file line #11: error inflating class android.widget.button e/androidruntime( 825): @ android.view.layoutinflater.createview(layoutinflater.java:606) e/androidruntime( 825): @ com.android.internal.policy.impl.phonelayoutinflater.oncreateview(phonelayoutinflater.java:56) e/androidruntime( 825): @ android.view.layoutinflater.oncreateview(layoutinflater.java:653) e/androidruntime( 825): @ android.view.layoutinflater.createviewfromtag(layoutinflater.java:678) e/androidruntime( 825): @ android.view.layoutinflater.rinflate(layoutinflater.java:739) e/androidruntime( 825): @ android.view.layoutinflater.rinflate(layoutinflater.java:742) e/androidruntime( 825): @ android.view.layoutinflater.parseinclude(layoutinflater.java:823) e/androidruntime( 825): @ android.view.layoutinflater.rinflate(layoutinflater.java:729) e/androidruntime( 825): @ android.view.layoutinflater.rinflate(layoutinflater.java:742) e/androidruntime( 825): @ android.view.layoutinflater.rinflate(layoutinflater.java:742) e/androidruntime( 825): @ android.view.layoutinflater.inflate(layoutinflater.java:489) e/androidruntime( 825): @ android.view.layoutinflater.inflate(layoutinflater.java:396) e/androidruntime( 825): @ android.view.layoutinflater.inflate(layoutinflater.java:352) e/androidruntime( 825): @ com.android.internal.policy.impl.phonewindow.setcontentview(phonewindow.java:251) e/androidruntime( 825): @ android.app.activity.setcontentview(activity.java:1835) e/androidruntime( 825): @ com.example.mainactivity.oncreate(mainactivity.java:96) e/androidruntime( 825): @ android.app.activity.performcreate(activity.java:4465) e/androidruntime( 825): @ android.app.instrumentation.callactivityoncreate(instrumentation.java:1049) e/androidruntime( 825): @ android.app.activitythread.performlaunchactivity(activitythread.java:1920) e/androidruntime( 825): ... 11 more e/androidruntime( 825): caused by: java.lang.reflect.invocationtargetexception e/androidruntime( 825): @ java.lang.reflect.constructor.constructnative(native method) e/androidruntime( 825): @ java.lang.reflect.constructor.newinstance(constructor.java:417) e/androidruntime( 825): @ android.view.layoutinflater.createview(layoutinflater.java:586) e/androidruntime( 825): ... 29 more e/androidruntime( 825): caused by: android.content.res.resources$notfoundexception: resource not drawable (color or path): typedvalue{t=0x1/d=0x7f02000d a=-1 r=0x7f02000d} e/androidruntime( 825): @ android.content.res.resources.loaddrawable(resources.java:1897) e/androidruntime( 825): @ android.content.res.typedarray.getdrawable(typedarray.java:601) e/androidruntime( 825): @ android.widget.textview.<init>(textview.java:620) e/androidruntime( 825): @ android.widget.button.<init>(button.java:108) e/androidruntime( 825): @ android.widget.button.<init>(button.java:104) e/androidruntime( 825): ... 32 more
my drawable resources in drawable-hdpi.
but if put drawables in drawable-* folder app runs. ui getting scattered.
does have idea, problem could. have add variable or flag in android.mk
=========edit========= app works fine if build eclipse. , run on same device. therefore issue might in building app along aosp. ========================
any highly appreciated.
regards, yuvi
so after struggling long , googling more 2 days, found issue. there no drawable-hdpi
folder in apk. have resolved issue adding local_aapt_flags += -c mdpi,hdpi,xhdpi
line in android.mk
file.
those struggling same kind of problem follow these supper steps:
check @ line giving error: binary xml file line #11: error inflating class android.widget.button
in xml file was:
<button android:id="@+id/btn_footer_back" style="@style/normalbuttonstyle" android:layout_width="wrap_content" android:layout_height="60px" android:layout_marginright="1dp" android:background="@drawable/button_state_selector" android:drawableleft="@drawable/ic_back" android:drawablepadding="10px" android:text="@string/back" android:visibility="gone" />
so, next step now, log tells story, check line:
caused by: android.content.res.resources$notfoundexception: resource not drawable (color or path): typedvalue{t=0x1/d=0x7f02000d a=-1 r=0x7f02000d}
here r=0x7f02000d
resource id, can find in yourproject/gen/r.java if search 0x7f02000d
in r.java able find resource creating problem, in case r.drawable.ic_back
hope helps other resolve problems.
regards, yuvi
Comments
Post a Comment