【问题标题】:android.view.InflateException: Binary XML file line #0: Error inflating classandroid.view.InflateException: Binary XML file line #0: Error inflating class
【发布时间】:2018-05-07 09:32:27
【问题描述】:

谁能告诉我这个布局有什么问题?因为我似乎找不到任何可能导致 InflateException 的异常情况。此外,我主要在三星设备上遇到此异常,其他设备似乎或多或少都可以正常工作。完全异常

致命异常:java.lang.RuntimeException 无法启动活动 ComponentInfo{类名}:android.view.InflateException:二进制 XML 文件第 0 行:膨胀 {类名} 时出错

 <?xml version="1.0" encoding="utf-8"?>
<android.support.constraint.ConstraintLayout   
    xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:app="http://schemas.android.com/apk/res-auto"
    android:id="@+id/loginContainer"
    style="@style/AuthenticationTheme"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:alpha="0">

    <LinearLayout
        android:id="@+id/holder"
        android:layout_width="0dp"
        android:layout_height="wrap_content"
        android:orientation="vertical"
        app:layout_constraintEnd_toEndOf="parent"
        app:layout_constraintStart_toStartOf="parent"
        app:layout_constraintTop_toTopOf="parent">

        <TextView
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:layout_marginTop="12dp"
            android:gravity="center"
            android:text="@string/window_enter_identifier_greeting_label"
            android:textAlignment="center"
            android:textSize="26sp" />

        <TextView
            android:id="@+id/info"
            style="@style/AuthenticationTheme"
            android:layout_width="match_parent"
            android:layout_height="50dp"
            android:layout_marginLeft="@dimen/authentication_margin_from_sides"
            android:layout_marginRight="@dimen/authentication_margin_from_sides"
            android:gravity="center"
            android:text="@string/window_enter_identifier_phone_description_label"
            android:textAlignment="center"
            android:textSize="16sp" />

        <LinearLayout
            android:id="@+id/phoneInputHolder"
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:orientation="vertical">

            <com.custom.authentication.views.IdentifierInputView
                android:id="@+id/authenticationInput"
                android:layout_width="match_parent"
                android:layout_height="wrap_content"
                android:layout_marginLeft="@dimen/authentication_margin_from_sides"
                android:layout_marginRight="@dimen/authentication_margin_from_sides" />

        </LinearLayout>
    </LinearLayout>

    <com.custom.authentication.views.BottomButtonsView
        android:id="@+id/bottomButtons"
        android:layout_width="0dp"
        android:layout_height="wrap_content"
        app:layout_constraintBottom_toBottomOf="parent"
        app:layout_constraintEnd_toEndOf="parent"
        app:layout_constraintStart_toStartOf="parent"
        app:linkText="@string/window_enter_identifier_login_with_email_button"
        app:mainText="@string/Continue" />

</android.support.constraint.ConstraintLayout>

我在我的自定义视图类中扩展了这个布局,如下所示:

class EnterIdentifierView(context: Context) : ConstraintLayout(context) {

    init {
        inflate(context, R.layout.view_enter_identifier, this)

    }    

并像这样创建我的自定义视图:

override fun onCreateControllerView(layoutInflater: LayoutInflater, viewParent: ViewGroup) = EnterIdentifierView(layoutInflater.context)

【问题讨论】:

  • 你能在你试图膨胀这个布局的地方添加代码吗,我们需要整个东西来帮助你:)。
  • @xoxel 我更新了我的帖子

标签: android xml android-constraintlayout inflate-exception


【解决方案1】:

我不认为这是一个答案,更多的是一个建议,但由于我没有足够的声誉,所以不得不这样发布。

根据我的经验,当我收到此类错误时,它有时表示 OutOfMemory 错误,请检查以确保您的自定义类没有尝试加载任何大图像等。

还要仔细检查完整的 Stacktrace,如果您可以访问一个,是否有任何 OOM

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2016-11-03
    • 2020-06-27
    • 1970-01-01
    • 2015-08-21
    • 2012-02-09
    • 2012-03-04
    相关资源
    最近更新 更多