1

I am having an Issue: android.view.InflateException: Binary XML file line #2: Binary XML file line #2: Error inflating class <unknown> On some devices.

It happens while inflating in Adapter in RecyclerView (As found from the log).

The crash happens in the following devices.

EDIT - All crashing devices have android 6

The crash does not happens in the following devices.

AdapterAnimationPicker.java

@Override
    public ViewHolder onCreateViewHolder(@NonNull ViewGroup parent, int viewType) {
        context = parent.getContext();

        // error happening below line
        View v = LayoutInflater.from(parent.getContext()).inflate(R.layout.card_animation_picker,parent,false);
        mFirebaseAnalytics = FirebaseAnalytics.getInstance(context);
        return new ViewHolder(v);
    }

card_animation_picker.xml

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:app="http://schemas.android.com/apk/res-auto"
    android:orientation="vertical"
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:clipToPadding="false"
    android:background="@drawable/rounded_corner_card_primary">

    <LinearLayout
        android:layout_height="wrap_content"
        android:layout_width="match_parent">
        <androidx.constraintlayout.widget.ConstraintLayout
            android:layout_width="match_parent"
            android:layout_height="wrap_content">
            <FrameLayout
                android:id="@+id/card_anim_picker_framelayout"
                android:background="@drawable/rounded_corner_card_primary"
                android:layout_width="0dp"
                android:layout_height="0dp"
                app:layout_constraintDimensionRatio="H,16:9"
                app:layout_constraintEnd_toEndOf="parent"
                app:layout_constraintStart_toStartOf="parent"
                app:layout_constraintTop_toTopOf="parent">
                <com.airbnb.lottie.LottieAnimationView
                    android:id="@+id/card_anim_picker_animation_view"
                    android:layout_width="match_parent"
                    android:layout_height="match_parent" />
            </FrameLayout>
        </androidx.constraintlayout.widget.ConstraintLayout>
    </LinearLayout>

    <com.github.florent37.expansionpanel.ExpansionLayout
        app:expansion_expanded="false"
        android:id="@+id/card_anim_picker_expansionLayout"
        android:layout_width="match_parent"
        android:layout_height="wrap_content">
        <LinearLayout
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:orientation="horizontal"
            android:padding="4dp">
            <Button
                app:cornerRadius="9999dp"
                app:rippleColor="@color/colorAccent"
                android:id="@+id/card_anim_picker_edit_btn"
                android:backgroundTint="@color/colorPrimaryLessLight"
                style="@style/Widget.MaterialComponents.Button.UnelevatedButton"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:layout_weight="1"
                android:text="edit"
                android:textColor="@color/colorAccent"/>
        </LinearLayout>
    </com.github.florent37.expansionpanel.ExpansionLayout>

</LinearLayout>

And here is the log files

FATAL EXCEPTION: main
Process: com.w3saver.typography, PID: 16223
android.view.InflateException: Binary XML file line #2: Binary XML file line #2: Error inflating class <unknown>
    at android.view.LayoutInflater.inflate(LayoutInflater.java:539)
    at android.view.LayoutInflater.inflate(LayoutInflater.java:423)
    at com.w3saver.typography.Adapters.AdapterAnimationPicker.onCreateViewHolder(AdapterAnimationPicker.java:52)
    at com.w3saver.typography.Adapters.AdapterAnimationPicker.onCreateViewHolder(AdapterAnimationPicker.java:27)
    at androidx.recyclerview.widget.RecyclerView$Adapter.createViewHolder(RecyclerView.java:6794)
    at androidx.recyclerview.widget.RecyclerView$Recycler.tryGetViewHolderForPositionByDeadline(RecyclerView.java:5975)
    at androidx.recyclerview.widget.RecyclerView$Recycler.getViewForPosition(RecyclerView.java:5858)
    at androidx.recyclerview.widget.RecyclerView$Recycler.getViewForPosition(RecyclerView.java:5854)
    at androidx.recyclerview.widget.LayoutState.next(LayoutState.java:100)
    at androidx.recyclerview.widget.StaggeredGridLayoutManager.fill(StaggeredGridLayoutManager.java:1609)
    at androidx.recyclerview.widget.StaggeredGridLayoutManager.onLayoutChildren(StaggeredGridLayoutManager.java:683)
    at androidx.recyclerview.widget.StaggeredGridLayoutManager.onLayoutChildren(StaggeredGridLayoutManager.java:605)
    at androidx.recyclerview.widget.RecyclerView.dispatchLayoutStep2(RecyclerView.java:3924)
    at androidx.recyclerview.widget.RecyclerView.onMeasure(RecyclerView.java:3336)
    at android.view.View.measure(View.java:18809)
    at android.view.ViewGroup.measureChildWithMargins(ViewGroup.java:5955)
    at android.widget.LinearLayout.measureChildBeforeLayout(LinearLayout.java:1465)
    at android.widget.LinearLayout.measureVertical(LinearLayout.java:748)
    at android.widget.LinearLayout.onMeasure(LinearLayout.java:630)
    at android.view.View.measure(View.java:18809)
    at android.view.ViewGroup.measureChildWithMargins(ViewGroup.java:5955)
    at android.widget.FrameLayout.onMeasure(FrameLayout.java:194)
    at androidx.appcompat.widget.ContentFrameLayout.onMeasure(ContentFrameLayout.java:143)
    at android.view.View.measure(View.java:18809)
    at android.view.ViewGroup.measureChildWithMargins(ViewGroup.java:5955)
    at android.widget.LinearLayout.measureChildBeforeLayout(LinearLayout.java:1465)
    at android.widget.LinearLayout.measureVertical(LinearLayout.java:748)
    at android.widget.LinearLayout.onMeasure(LinearLayout.java:630)
    at android.view.View.measure(View.java:18809)
    at android.view.ViewGroup.measureChildWithMargins(ViewGroup.java:5955)
    at android.widget.FrameLayout.onMeasure(FrameLayout.java:194)
    at android.view.View.measure(View.java:18809)
    at android.view.ViewGroup.measureChildWithMargins(ViewGroup.java:5955)
    at android.widget.LinearLayout.measureChildBeforeLayout(LinearLayout.java:1465)
    at android.widget.LinearLayout.measureVertical(LinearLayout.java:748)
    at android.widget.LinearLayout.onMeasure(LinearLayout.java:630)
    at android.view.View.measure(View.java:18809)
    at android.view.ViewGroup.measureChildWithMargins(ViewGroup.java:5955)
    at android.widget.FrameLayout.onMeasure(FrameLayout.java:194)
    at com.android.internal.policy.PhoneWindow$DecorView.onMeasure(PhoneWindow.java:2643)
    at android.view.View.measure(View.java:18809)
    at android.view.ViewRootImpl.performMeasure(ViewRootImpl.java:2112)
    at android.view.ViewRootImpl.measureHierarchy(ViewRootImpl.java:1228)
    at android.view.ViewRootImpl.performTraversals(ViewRootImpl.java:1464)
    at android.view.ViewRootImpl.doTraversal(ViewRootImpl.java:1119)
    at android.view.ViewRootImpl$TraversalRunnable.run(ViewRootImpl.java:6060)
    at android.view.Choreographer$CallbackRecord.run(Choreographer.java:858)
    at android.view.Choreographer.doCallbacks(Choreographer.java:670)
    at android.view.Choreographer.doFrame(Choreographer.java:606)
    at android.view.Choreographer$FrameDisplayEventReceiver.run(Choreographer.java:844)
    at android.os.Handler.handleCallback(Handler.java:746)
    at android.os.Handler.dispatchMessage(Handler.java:95)
    at android.os.Loo

Thnings that i have already tried

I have no idea what is wrong with my code i am digging this issue from last 2 days. If someone help fegureit out then that would be so helpful.

5
  • 1
    android:background="@drawable/rounded_corner_card_primary" remove the above line and test once is it working? If yes please mention in comment will give you solution Commented Aug 8, 2019 at 5:08
  • okay will get back to you after testing, Thanks Commented Aug 8, 2019 at 5:18
  • @AbhinavGupta I have removed this line android:background="@drawable/rounded_corner_card_primary" and my code is running fine now thanks. but what is the solution here? Commented Aug 8, 2019 at 10:25
  • use png file in drawable not in drwable-24 but one thing paste in xxhdpi then test in all devices. Definitely, it will work in all devices. If it is not an image only shape thing please share that xml in your question @KartikGarasia Commented Aug 8, 2019 at 10:34
  • hey that solved my problem.. please answer it on answer section I will accept it so other people can find the solution more easily. Commented Aug 12, 2019 at 10:40

2 Answers 2

1

Try this :

use png file in drawable not in drwable-24 but one thing paste in xxhdpi then test in all devices. Definitely, it will work in all devices. If it is not an image only shape thing please share that xml in your question.

Happy Coding :)

Sign up to request clarification or add additional context in comments.

Comments

1

android:background="@drawable/rounded_corner_card_primary"

Probably this is the problem. If this is an SVG file and you are using Offset property in this file it will crash in marshmallow. So better make a sperate file for marshmallow devices and use png file.

Refer https://developer.android.com/reference/android/graphics/drawable/VectorDrawable.html

2 Comments

No i am just using radius and shape property and it is xml file
Add that as well. Whatever you are using.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.