Home android.view.InflateException: Binary XML file line #0: Binary XML file line #0: Error inflating class android.support.v7.widget.CardView
Reply: 1

android.view.InflateException: Binary XML file line #0: Binary XML file line #0: Error inflating class android.support.v7.widget.CardView

phfatballz
1#
phfatballz Published in 2018-01-13 06:16:25Z

Hi I am creating a contact app and have been having an issue when transitioning into a new fragment. I have been 10 hours on this issue, it's driving me to the walls.

As soon as I started like I was learning, I ran into this issue and at a complete loss as to what I should do. If anyone could provide pointers, I would very much appreciate it.

Here is the java class of the codes:

public class ContactPropertyListAdapter extends ArrayAdapter<String> {


    private LayoutInflater mInflater;
    private List<String> mProperties = null;
    private int layoutResource;
    private Context mContext;
    private String mAppend;


    public ContactPropertyListAdapter(@NonNull Context context, @LayoutRes int resource, @NonNull List<String> properties) {
        super(context, resource, properties);
        mInflater = (LayoutInflater) context.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
        layoutResource = resource;
        this.mContext = context;
        this.mProperties = properties;

    }

    //------------------ Stuff to change ---------------------------------------------------

    // in replacement of recycler view
    //change if more widgets wants to be added
    private static class ViewHolder {
        TextView property;
        ImageView rightIcon;
        ImageView leftIcon;

    }
    //--------------------------------------------------------------------------------------

    @NonNull
    @Override
    public View getView(int position, @Nullable View convertView, @NonNull ViewGroup parent) {
        /**
         ******* ViewHolder Build Pattern Start *******
         */

        // view holds widget in memory ahead of time for efficiency
        final ViewHolder holder;


        !! WHERE ERROR BEGINS !!
        if(convertView == null){
            convertView = mInflater.inflate(layoutResource, parent, false);
            holder = new ViewHolder();

            //------------------ Stuff to change ---------------------------------------------------
            holder.property = (TextView) convertView.findViewById(R.id.tvMiddleCardView);
            holder.rightIcon = (ImageView) convertView.findViewById(R.id.iconRightCardView);
            holder.leftIcon = (ImageView) convertView.findViewById(R.id.iconLeftCardView);
            //--------------------------------------------------------------------------------------

            //used to store view
            convertView.setTag(holder);
        }
        else{
            holder = (ViewHolder) convertView.getTag();
        }

        //------------------ Stuff to change ---------------------------------------------------

        final String property = getItem(position);
        holder.property.setText(property);


        //check if it's an email or a phone number
        //email
        if(property.contains("@")) {
            holder.leftIcon.setImageResource(mContext.getResources().getIdentifier("@drawable/ic_email", null, mContext.getPackageName()));
        }
        else if((property.length() != 0)){
            holder.leftIcon.setImageResource(mContext.getResources().getIdentifier("@drawable/ic_phone", null, mContext.getPackageName()));
            holder.rightIcon.setImageResource(mContext.getResources().getIdentifier("@drawable/ic_message", null, mContext.getPackageName()));
        }

        //--------------------------------------------------------------------------------------

        return convertView;
    }
}

The logcat message:

FATAL EXCEPTION: main
Process: com.example.joon.contactslist, PID: 3250


android.view.InflateException: Binary XML file line #0: Binary XML file line #0: Error inflating class android.support.v7.widget.CardView
at android.view.LayoutInflater.inflate(LayoutInflater.java:539)
at android.view.LayoutInflater.inflate(LayoutInflater.java:423)
at com.example.joon.contactslist.Utils.ContactPropertyListAdapter.getView(ContactPropertyListAdapter.java:74)
at android.widget.AbsListView.obtainView(AbsListView.java:2346)
at android.widget.ListView.makeAndAddView(ListView.java:1875)
at android.widget.ListView.fillDown(ListView.java:702)
at android.widget.ListView.fillFromTop(ListView.java:763)
at android.widget.ListView.layoutChildren(ListView.java:1684)
at android.widget.AbsListView.onLayout(AbsListView.java:2148)
at android.view.View.layout(View.java:16630)
at android.view.ViewGroup.layout(ViewGroup.java:5437)
at android.widget.RelativeLayout.onLayout(RelativeLayout.java:1079)
at android.view.View.layout(View.java:16630)
at android.view.ViewGroup.layout(ViewGroup.java:5437)
at android.widget.RelativeLayout.onLayout(RelativeLayout.java:1079)
at android.view.View.layout(View.java:16630)
at android.view.ViewGroup.layout(ViewGroup.java:5437)
at android.support.design.widget.CoordinatorLayout.layoutChild(CoordinatorLayout.java:1166)
at android.support.design.widget.CoordinatorLayout.onLayoutChild(CoordinatorLayout.java:851)
at android.support.design.widget.CoordinatorLayout.onLayout(CoordinatorLayout.java:870)
at android.view.View.layout(View.java:16630)
at android.view.ViewGroup.layout(ViewGroup.java:5437)
at android.widget.FrameLayout.layoutChildren(FrameLayout.java:336)
at android.widget.FrameLayout.onLayout(FrameLayout.java:273)
at android.view.View.layout(View.java:16630)
at android.view.ViewGroup.layout(ViewGroup.java:5437)
at android.support.design.widget.CoordinatorLayout.layoutChild(CoordinatorLayout.java:1166)
at android.support.design.widget.CoordinatorLayout.onLayoutChild(CoordinatorLayout.java:851)
at android.support.design.widget.CoordinatorLayout.onLayout(CoordinatorLayout.java:870)
at android.view.View.layout(View.java:16630)
at android.view.ViewGroup.layout(ViewGroup.java:5437)
at android.widget.FrameLayout.layoutChildren(FrameLayout.java:336)
at android.widget.FrameLayout.onLayout(FrameLayout.java:273)
at android.view.View.layout(View.java:16630)
at android.view.ViewGroup.layout(ViewGroup.java:5437)
at android.widget.LinearLayout.setChildFrame(LinearLayout.java:1743)
at android.widget.LinearLayout.layoutVertical(LinearLayout.java:1586)
at android.widget.LinearLayout.onLayout(LinearLayout.java:1495)
at android.view.View.layout(View.java:16630)
at android.view.ViewGroup.layout(ViewGroup.java:5437)
at android.widget.FrameLayout.layoutChildren(FrameLayout.java:336)
at android.widget.FrameLayout.onLayout(FrameLayout.java:273)
at android.view.View.layout(View.java:16630)
at android.view.ViewGroup.layout(ViewGroup.java:5437)
at android.widget.LinearLayout.setChildFrame(LinearLayout.java:1743)
at android.widget.LinearLayout.layoutVertical(LinearLayout.java:1586)
at android.widget.LinearLayout.onLayout(LinearLayout.java:1495)
at android.view.View.layout(View.java:16630)
at android.view.ViewGroup.layout(ViewGroup.java:5437)
at android.widget.FrameLayout.layoutChildren(FrameLayout.java:336)
at android.widget.FrameLayout.onLayout(FrameLayout.java:273)
at com.android.internal.policy.PhoneWindow$DecorView.onLayout(PhoneWindow.java:2678)
at android.view.View.layout(View.java:16630)
at android.view.ViewGroup.layout(ViewGroup.java:5437)
at android.view.ViewRootImpl.performLayout(ViewRootImpl.java:2171)
at android.view.ViewRootImpl.performTraversals(ViewRootImpl.java:1931)
at android.view.ViewRootImpl.doTraversal(ViewRootImpl.java:1107)
at android.view.ViewRootImpl$TraversalRunnable.run(ViewRootImpl.java:6013)
at android.view.Choreographer$CallbackRecord.run(Choreographer.java:858)
at android.view.Choreographer.doCallbacks(Choreographer.java:67
01-12 22:05:50.442 1653-1664/system_process W/ActivityManager:   Force finishing activity com.example.joon.contactslist/.MainActivity
01-12 22:05:50.448 1228-1339/? D/PermissionCache: checking android.permission.READ_FRAME_BUFFER for uid=1000 => granted (312 us)
01-12 22:05:50.456 1228-1339/? D/gralloc_ranchu: gralloc_alloc: Creating ashmem region of size 1327104

As well as the relating 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="match_parent"
    xmlns:app="http://schemas.android.com/apk/res-auto">

    <android.support.v7.widget.CardView
        android:layout_width="match_parent"
        android:layout_height="60dp"
        android:id="@+id/cardView"
        app:cardElevation="3dp"
        android:layout_margin="10dp"
        android:layout_marginTop="30dp"
        android:background="@drawable/grey_border">

        <RelativeLayout
            android:layout_width="match_parent"
            android:layout_height="match_parent">

            <ImageView
                android:layout_width="30dp"
                android:layout_height="30dp"
                android:layout_marginStart="20dp"
                android:id="@+id/iconLeftCardView"
                android:layout_centerVertical="true"/>

            <TextView
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:textSize="15sp"
                android:textColor="@color/black"
                android:layout_centerInParent="true"
                android:id="@+id/tvMiddleCardView"/>

            <ImageView
                android:layout_width="30dp"
                android:layout_height="30dp"
                android:layout_marginEnd="20dp"
                android:layout_alignParentRight="true"
                android:id="@+id/iconRightCardView"
                android:layout_centerVertical="true"/>

        </RelativeLayout>

    </android.support.v7.widget.CardView>

</RelativeLayout>

My grade looks like the following:

apply plugin: 'com.android.application'

android {
    compileSdkVersion 26
    defaultConfig {
        applicationId "com.example.joon.contactslist"
        minSdkVersion 20
        targetSdkVersion 26
        versionCode 1
        versionName "1.0"
        testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner"
    }
    buildTypes {
        release {
            minifyEnabled false
            proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
        }
    }
}

dependencies {
    implementation fileTree(dir: 'libs', include: ['*.jar'])
    implementation 'com.android.support:appcompat-v7:26.1.0'
    implementation 'com.android.support.constraint:constraint-layout:1.0.2'
    testImplementation 'junit:junit:4.12'
    androidTestImplementation 'com.android.support.test:runner:1.0.1'
    androidTestImplementation 'com.android.support.test.espresso:espresso-core:3.0.1'

    compile "com.android.support:support-core-utils:26.1.0"

    //Android Support Design Library
    compile 'com.android.support:design:26.1.0'

    //Universal Image Loader
    compile 'com.nostra13.universalimageloader:universal-image-loader:1.9.5'

    //Circle ImageView library
    compile 'de.hdodenhof:circleimageview:2.2.0'

    //Cardview library
    compile 'com.android.support:cardview-v7:26.1.0'





}
Munir
2#
Munir Reply to 2018-01-13 06:40:19Z

I think android:background="@drawable/grey_border" causes the issue.remove it and try

<android.support.v7.widget.CardView
        android:layout_width="match_parent"
        android:layout_height="60dp"
        android:id="@+id/cardView"
        app:cardElevation="3dp"
        android:layout_margin="10dp"
        android:layout_marginTop="30dp">
You need to login account before you can post.

About| Privacy statement| Terms of Service| Advertising| Contact us| Help| Sitemap|
Processed in 0.316243 second(s) , Gzip On .

© 2016 Powered by mzan.com design MATCHINFO