0

I have this layout:

<?xml version="1.0" encoding="utf-8"?>
<merge>
  <android.support.constraint.ConstraintLayout
      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"
      android:id="@+id/has_selected_account"
      android:layout_width="match_parent"
      android:layout_height="wrap_content">

    <TextView
        android:id="@+id/account_display_name"
        android:layout_width="wrap_content"
        android:layout_marginTop="@dimen/account_menu_name_and_display_vertical_padding"
        android:layout_marginBottom="@dimen/account_menu_name_and_display_vertical_padding"
        app:layout_constraintBottom_toTopOf="@+id/account_name"
        app:layout_constraintEnd_toEndOf="parent"
        app:layout_constraintTop_toTopOf="parent"
        app:layout_constraintVertical_chainStyle="packed"
        tools:text="DisplayNameIsLongSoItShouldBeTruncatedAtSomePoint"/>
    <TextView
        android:id="@+id/account_name"
        android:layout_width="wrap_content"
        android:layout_marginTop="@dimen/account_menu_name_and_display_vertical_padding"
        android:layout_marginBottom="@dimen/account_menu_name_and_display_vertical_padding"
        android:includeFontPadding="false"
        app:layout_constraintBottom_toBottomOf="parent"
        app:layout_constraintEnd_toEndOf="parent"
        app:layout_constraintTop_toBottomOf="@+id/account_display_name"
        tools:text="[email protected]"/>
  </android.support.constraint.ConstraintLayout>
</merge>

And I get a very general inflation error:

 Caused by: android.view.InflateException: Binary XML file line #39: Error inflating class com.me.AccountParticle
    at android.view.LayoutInflater.createView(Layo

(Cut like this)

I have tried to simplify my XML. How can I tackle the inflation error?

Plus my layout XML doesn't have like #39 so where does this refer to?

2 Answers 2

2

You're missing android:layout_height for both TextView, that's how you get view inflation error. When the view is being inflated, it needs to resolve the merge tag possibly by another class or method, which seems to have a different way of parsing errors. Otherwise you would have seen a clearer error with android:layout_height being missing.

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

4 Comments

how could i have debugged it?
It could have shown you a clearer error, but because of merge tag it can become unclear when it is delegated to whichever the class is parsing it.
so i could just paste the xml instead of using the merge.
Using merge is one way to optimize your views, and so it's fine using merge. I think the IDE or Android Studio should have given you the warnings when missing one of the important attributes. Maybe there's a plugin for it, but whenever there's a view inflation error, chances are it's within the XML layouts.
0

Please use this.

<?xml version="1.0" encoding="utf-8"?>
<merge>
  <android.support.constraint.ConstraintLayout
      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"
      android:id="@+id/has_selected_account"
      android:layout_width="match_parent"
      android:layout_height="wrap_content">

    <TextView
        android:id="@+id/account_display_name"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_marginTop="@dimen/account_menu_name_and_display_vertical_padding"
        android:layout_marginBottom="@dimen/account_menu_name_and_display_vertical_padding"
        app:layout_constraintBottom_toTopOf="@+id/account_name"
        app:layout_constraintEnd_toEndOf="parent"
        app:layout_constraintTop_toTopOf="parent"
        app:layout_constraintVertical_chainStyle="packed"
        tools:text="DisplayNameIsLongSoItShouldBeTruncatedAtSomePoint"/>
    <TextView
        android:id="@+id/account_name"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_marginTop="@dimen/account_menu_name_and_display_vertical_padding"
        android:layout_marginBottom="@dimen/account_menu_name_and_display_vertical_padding"
        android:includeFontPadding="false"
        app:layout_constraintBottom_toBottomOf="parent"
        app:layout_constraintEnd_toEndOf="parent"
        app:layout_constraintTop_toBottomOf="@+id/account_display_name"
        tools:text="[email protected]"/>
  </android.support.constraint.ConstraintLayout>
</merge>

Comments

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.