Android Team
Android Team

Reputation: 21

Android.view.InflateException: Binary XML file line #25: Error inflating class ImageButton, Resource NotFoundException, XmlPullParserException

In API: 19 Iam facing this Inflate Exception but Iam using AppCompatDrawableManager which supports as vector drawables in API:19

three Exceptions 1. Error in Inflate Image button 2. Resources$NotFoundException File res/drawable/bckg_icon.xml from drawable resource
3. org.xmlpull.v1.XmlPullParserException: Binary XML file line #1: invalid drawable tag vector

I have tried to decerese the ImageButton drawable src which four formats(hdpi,mdpi,xxhdpi etc) my Implementation : xml File which is fragmnet xml layout:

<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:id="@+id/layoutPreviewActionBar"
android:layout_width="match_parent"
android:layout_height="match_parent">


 <RelativeLayout
    android:id="@+id/previewFragment"
    android:layout_width="fill_parent"
    android:layout_height="@dimen/action_bar_height"
    android:layout_alignParentBottom="true"
    android:layout_centerHorizontal="true">
     <TextView
         android:layout_width="wrap_content" 
         android:layout_height="wrap_content"
         android:layout_alignParentBottom="true" 
         android:layout_marginBottom="25dp"
         android:layout_marginLeft="10dp"
         android:text="00:00"
         android:id="@+id/timeduration"
         android:textColor="@color/colorPrimary"/>
     <ImageButton
         android:id="@+id/localVideo"
         android:layout_width="@dimen/icon_width"
         android:layout_height="@dimen/icon_height"
         android:layout_centerVertical="true"
         android:layout_marginRight="14.1dp"
         android:layout_toLeftOf="@+id/call"
         android:background="@drawable/bckg_icon"
         android:layout_margin="5dp"
         android:src="@drawable/video_icon" />

     <ImageButton
         android:id="@+id/call"
         android:layout_width="@dimen/icon_width"
         android:layout_height="@dimen/icon_height"
         android:layout_centerHorizontal="true"
         android:layout_centerVertical="true"
         android:background="@drawable/initiate_call_button"
         android:clickable="true"
         android:layout_margin="5dp"
         app:srcCompat="@drawable/start_call" />

     <ImageButton
         android:id="@+id/localAudio"
         android:layout_width="@dimen/icon_width"
         android:layout_height="@dimen/icon_height"
         android:layout_centerVertical="true"
         android:layout_marginLeft="14.1dp"
         android:layout_toRightOf="@+id/call"
         android:background="@drawable/bckg_icon"
         app:srcCompat="@drawable/mic_icon" />
</RelativeLayout>

My Fragment java class those drawables implementation :

rootView = inflater.inflate(R.layout.preview_actionbar_fragment, container, false);
    mAudioBtn = (ImageButton)rootView.findViewById(R.id.localAudio);
    mVideoBtn = (ImageButton)rootView.findViewById(R.id.localVideo);
    mCallBtn = (ImageButton)rootView.findViewById(R.id.call);
    timdura= (TextView)rootView.findViewById(R.id.timeduration); 
    c=mActivity;
    booking_id=mActivity.bookingId;
    drawableStartCall = AppCompatDrawableManager.get().getDrawable(mActivity,R.drawable.initiate_call_button);
    drawableEndCall =AppCompatDrawableManager.get().getDrawable(mActivity,R.drawable.end_call_button);
    drawableBckBtn = AppCompatDrawableManager.get().getDrawable(mActivity,R.drawable.bckg_icon);

My logCat details:

   I/com. .MainActivity: OnAttach PreviewControlFragment
   I/com.therightdoctors.dpmdoctor.MainActivity: OnCreate PreviewControlFragment
   D/AndroidRuntime: Shutting down VM
   W/dalvikvm: threadid=1: thread exiting with uncaught exception (group=0x41a22cf8)
   W/dalvikvm: threadid=1: uncaught exception occurred

   E/UncaughtException: java.lang.RuntimeException: Unable to start activity ComponentInfo{com.therightdoctors.dpmdoctor/com.therightdoctors.dpmdoctor.MainActivity}: android.view.InflateException: Binary XML file line #25: Error inflating class ImageButton
                                                                                  at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2377)
                                                                                  at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2429)
                                                                                  at android.app.ActivityThread.access$800(ActivityThread.java:151)
                                                                                  at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1342)
                                                                                  at android.os.Handler.dispatchMessage(Handler.java:110)
                                                                                  at android.os.Looper.loop(Looper.java:193)
                                                                                  at android.app.ActivityThread.main(ActivityThread.java:5333)
                                                                                  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:829)
                                                                                  at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:645)
                                                                                  at dalvik.system.NativeStart.main(Native Method)
                                                                               Caused by: android.view.InflateException: Binary XML file line #25: Error inflating class ImageButton
                                                                                  at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:713)
                                                                                  at android.view.LayoutInflater.rInflate(LayoutInflater.java:755)
                                                                                  at android.view.LayoutInflater.rInflate(LayoutInflater.java:758)
                                                                                  at android.view.LayoutInflater.inflate(LayoutInflater.java:492)
                                                                                  at android.view.LayoutInflater.inflate(LayoutInflater.java:397)
                                                                                  at com.therightdoctors.dpmdoctor.ui.PreviewControlFragment.onCreateView(PreviewControlFragment.java:165)
                                                                                  at android.support.v4.app.Fragment.performCreateView(Fragment.java:2192)
                                                                                  at android.support.v4.app.FragmentManagerImpl.moveToState(FragmentManager.java:1299)
                                                                                  at android.support.v4.app.FragmentManagerImpl.moveFragmentToExpectedState(FragmentManager.java:1528)
                                                                                  at android.support.v4.app.FragmentManagerImpl.moveToState(FragmentManager.java:1595)
                                                                                  at android.support.v4.app.BackStackRecord.executeOps(BackStackRecord.java:758)
                                                                                  at android.support.v4.app.FragmentManagerImpl.executeOps(FragmentManager.java:2363)
                                                                                  at android.support.v4.app.FragmentManagerImpl.executeOpsTogether(FragmentManager.java:2149)
                                                                                  at android.support.v4.app.FragmentManagerImpl.optimizeAndExecuteOps(FragmentManager.java:2103)
                                                                                  at android.support.v4.app.FragmentManagerImpl.execPendingActions(FragmentManager.java:2013)
                                                                                  at android.support.v4.app.FragmentController.execPendingActions(FragmentController.java:388)
                                                                                  at android.support.v4.app.FragmentActivity.onStart(FragmentActivity.java:607)
                                                                                  at android.support.v7.app.AppCompatActivity.onStart(AppCompatActivity.java:178)
                                                                                  at android.app.Instrumentation.callActivityOnStart(Instrumentation.java:1174)
                                                                                  at android.app.Activity.performStart(Activity.java:5353)
                                                                                  at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2340)
                                                                                  at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2429) 
                                                                                  at android.app.ActivityThread.access$800(ActivityThread.java:151) 
                                                                                  at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1342) 
                                                                                  at android.os.Handler.dispatchMessage(Handler.java:110) 
                                                                                  at android.os.Looper.loop(Looper.java:193) 
                                                                                  at android.app.ActivityThread.main(ActivityThread.java:5333) 
                                                                                  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:829) 
                                                                                  at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:645) 
                                                                                  at dalvik.system.NativeStart.main(Native Method) 
                                                                               Caused by: android.content.res.Resources$NotFoundException: File res/drawable/bckg_icon.xml from drawable resource ID #0x7f02005c
                                                                                  at android.content.res.Resources.loadDrawable(Resources.java:2170)
                                                                                  at android.content.res.TypedArray.getDrawable(TypedArray.java:602)
                                                                                  at android.view.View.<init>(View.java:3579)
                                                                                  at android.widget.ImageView.<init>(ImageView.java:123)
                                                                                  at android.widget.ImageButton.<init>(ImageButton.java:87)
                                                                                  at android.support.v7.widget.AppCompatImageButton.<init>(AppCompatImageButton.java:60)
                                                                                  at android.support.v7.widget.AppCompatImageButton.<init>(AppCompatImageButton.java:56)
                                                                                  at android.support.v7.app.AppCompatViewInflater.createView(AppCompatViewInflater.java:118)
                                                                                  at android.support.v7.app.AppCompatDelegateImplV9.createView(AppCompatDelegateImplV9.java:1029)
                                                                                  at android.support.v7.app.AppCompatDelegateImplV9.onCreateView(AppCompatDelegateImplV9.java:1087)
                                                                                  at android.support.v4.view.LayoutInflaterCompatHC$FactoryWrapperHC.onCreateView(LayoutInflaterCompatHC.java:47)
                                                                                  at android.view.LayoutInflater$FactoryMerger.onCreateView(LayoutInflater.java:172)
                                                                                  at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:684)
                                                                                  at android.view.LayoutInflater.rInflate(LayoutInflater.java:755) 
                                                                                  at android.view.LayoutInflater.rInflate(LayoutInflater.java:758) 
                                                                                  at android.view.LayoutInflater.inflate(LayoutInflater.java:492) 
                                                                                  at android.view.LayoutInflater.inflate(LayoutInflater.java:397) 
                                                                                  at com.therightdoctors.dpmdoctor.ui.PreviewControlFragment.onCreateView(PreviewControlFragment.java:165) 
                                                                                  at android.support.v4.app.Fragment.performCreateView(Fragment.java:2192) 
                                                                                  at android.support.v4.app.FragmentManagerImpl.moveToState(FragmentManager.java:1299) 
                                                                                  at android.support.v4.app.FragmentManagerImpl.moveFragmentToExpectedState(FragmentManager.java:1528) 
                                                                                  at android.support.v4.app.FragmentManagerImpl.moveToState(FragmentManager.java:1595) 
                                                                                  at android.support.v4.app.BackStackRecord.executeOps(BackStackRecord.java:758) 
                                                                                  at android.support.v4.app.FragmentManagerImpl.executeOps(FragmentManager.java:2363) 
                                                                                  at android.support.v4.app.FragmentManagerImpl.executeOpsTogether(FragmentManager.java:2149) 
                                                                                  at android.support.v4.app.FragmentManagerImpl.optimizeAndExecuteOps(FragmentManager.java:2103) 
                                                                                  at android.support.v4.app.FragmentManagerImpl.execPendingActions(FragmentManager.java:2013) 
                                                                                  at android.support.v4.app.FragmentController.execPendingActions(FragmentController.java:388) 
                                                                                  at android.support.v4.app.FragmentActivity.onStart(FragmentActivity.java:607) 
                                                                                  at android.support.v7.app.AppCompatActivity.onStart(AppCompatActivity.java:178) 
                                                                                  at android.app.Instrumentation.callActivityOnStart(Instrumentation.java:1174) 
                                                                                  at android.app.Activity.performStart(Activity.java:5353) 
                                                                                  at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2340) 
                                                                                  at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2429) 
                                                                                  at android.app.ActivityThread.access$800(ActivityThread.java:151) 
                                                                                  at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1342) 
                                                                                  at android.os.Handler.dispatchMessage(Handler.java:110) 
                                                                                  at android.os.Looper.loop(Looper.java:193) 
                                                                                  at android.app.ActivityThread.main(ActivityThread.java:5333) 
                                                                                  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:829) 
                                                                                  at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:645) 
                                                                                  at dalvik.system.NativeStart.main(Native Method) 
                                                                               Caused by: org.xmlpull.v1.XmlPullParserException: Binar

I have tried from StackOverflow some similar Question not working

  1. to reduce the images sizes ,

2.use app:srcCompat instead of android:src attribute in XML

problem only in API:19 lower DPI devices how to Handle these type of Exceptions

Upvotes: 2

Views: 3403

Answers (2)

MHM
MHM

Reputation: 894

I know it's been a while but I think that you are using a VectorDrawable as background of your ImageButton in here:

<ImageButton
     android:id="@+id/localVideo"
     android:layout_width="@dimen/icon_width"
     android:layout_height="@dimen/icon_height"
     android:layout_centerVertical="true"
     android:layout_marginRight="14.1dp"
     android:layout_toLeftOf="@+id/call"
     android:layout_margin="5dp"
     android:src="@drawable/video_icon"
     android:background="@drawable/bckg_icon />"   <!-- <- here is your problem -->

I figured out that using VectorDrawable as background of TextView, EditText, Button, ImageButton, etc using android:background="..." cause a crash on API 19 and before, Because android:background on older devices is using old APIs and when android tries to inflate your VectorDrawable it can not parse it and crashes. Note that when you are using app:srcCompat as the source image of your ImageView you are using Compat library and there is no problem. For fixing this you can use one of 3 methods:

  1. Use an ImageView behind your view and set its app:srcCompat to your VectorDrawable
  2. Use a custom widget that loads VectorDrawable using Compat library in runtime and sets the background
  3. Use alternative resources to set background of your View to your VectorDrawable in API 21 and above and set it to a BitmapDrawable (png file for example) in lower APIs.

Upvotes: 4

Aashish Aadarsh
Aashish Aadarsh

Reputation: 491

Once I had faced same issue, You can try anyone of the following methods :

  • Use .png or .jpeg instead of xml, and make sure the drawables are copied to drawable folder ( sometime it copies to drawable(v21) folder and then these images will not be available for API below 21).
  • Check the same thing for .xml drawables, in which directory it is kept.(You can view directory structure by changing view from Android to ProjectYou can see this image

  • Use srcCompat instead of src in xml files. You may need to declare

    compile 'com.android.support:support-vector-drawable:23.4.0'

Upvotes: 2

Related Questions