【问题标题】:android.view.InflateException in android studioandroid工作室中的android.view.InflateException
【发布时间】:2018-01-10 14:38:25
【问题描述】:

android.view.InflateException: Binary XML file line #32: Binary XML file line #32: Error inflating class

protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    try{
        setContentView(R.layout.installation_dialog);//error occured at this line.

这是我的 xml 文件

<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:card_view="http://schemas.android.com/apk/res-auto"
android:layout_width="match_parent"
android:layout_height="match_parent">

<android.support.v7.widget.CardView
    android:id="@+id/card_view"
    android:layout_width="fill_parent"
    android:layout_height="wrap_content"
    android:layout_gravity="center"
    android:layout_marginTop="@dimen/activity_horizontal_margin"
    android:layout_marginBottom="@dimen/activity_horizontal_margin"
    android:layout_marginLeft="@dimen/activity_custom_margin"
    android:layout_marginRight="@dimen/activity_custom_margin"
    android:layout_weight="0.54"
    card_view:cardElevation="@dimen/cardview_default_elevation"
    card_view:contentPadding="10dp">


    <TableLayout
        android:layout_width="match_parent"
        android:layout_height="wrap_content">


        <TableRow
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:layout_weight="1">

            <android.support.design.widget.TextInputLayout
                android:id="@+id/input_layout_Insta_Activities"
                android:layout_width="match_parent"
                android:layout_height="wrap_content"
                android:layout_marginTop="5dp"
                android:layout_weight="1">

                <EditText
                    android:id="@+id/etInstaActivities"
                    android:layout_width="match_parent"
                    android:layout_height="wrap_content"
                    android:layout_weight="1"
                    android:hint="Activity Name"
                    android:textColorHint="@color/accent"
                    android:textColor="@color/black"
                    />

            </android.support.design.widget.TextInputLayout>

        </TableRow>
        <TableRow
            android:layout_width="match_parent"
            android:layout_height="match_parent"
            android:layout_weight="1"
            >
            <Spinner
                android:id="@+id/SpInstaStatus"
                android:layout_width="0dp"
                android:layout_height="wrap_content"
                android:layout_weight="0.7" />
            <android.support.design.widget.TextInputLayout
                android:id="@+id/input_layout_InstaSpentHrs"
                android:layout_width="match_parent"
                android:layout_height="wrap_content"
                android:layout_weight="0.3">

                <EditText
                    android:id="@+id/etInstaSpentHrs"
                    android:layout_width="match_parent"
                    android:layout_height="wrap_content"
                    android:layout_weight="0.3"
                    android:editable="false"
                    android:focusable="false"
                    android:hint="Spent Hrs"
                    android:textColor="@android:color/black"
                    android:theme="@style/AutocompleteTheme" />
            </android.support.design.widget.TextInputLayout>
        </TableRow>

        <TableRow
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:layout_weight="1">

            <android.support.design.widget.TextInputLayout
                android:id="@+id/input_layout_InstaReason"
                android:layout_width="match_parent"
                android:layout_height="wrap_content"
                android:layout_below="@+id/LLHrs"
                android:layout_marginTop="10dp"
                android:layout_weight="1">

                <EditText
                    android:id="@+id/edReworkReason"
                    android:layout_width="match_parent"
                    android:layout_height="wrap_content"
                    android:layout_weight="1"
                    android:ems="11"
                    android:hint="Reason for Rework"
                    android:inputType="textMultiLine"
                    android:theme="@style/AutocompleteTheme" />
            </android.support.design.widget.TextInputLayout>
        </TableRow>

        <TableRow
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:layout_marginTop="5dp"
            android:layout_weight="1">

            <Button
                android:id="@+id/btn_instal_ok"
                android:layout_width="0dp"
                android:layout_height="wrap_content"
                android:layout_gravity="center"
                android:layout_weight="0.5"
                android:gravity="center"
                android:text="@string/OK"
                android:textColor="@color/white"
                android:theme="@style/CustomButtonStyle"/>

            <Button
                android:id="@+id/btn_instal_cancel"
                android:layout_width="0dp"
                android:layout_height="wrap_content"
                android:layout_weight="0.5"
                android:text="@string/Cancel"
                android:textColor="@color/white"
                android:theme="@style/CustomButtonStyle"/>
        </TableRow>
    </TableLayout>

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

我已经看到了一些例子,并且我已经尝试了这些解决方案。但是我没有解决。I have studied the solution in this link, but did not resolve the issue

任何人都可以帮助我。

【问题讨论】:

标签: android xml android-layout android-studio


【解决方案1】:

根据documentation,您应该使用 android.support.design.widget.TextInputEditText 作为 android.support.design.widget.TextInputLayout 的子级。

它看起来像:

 <android.support.design.widget.TextInputLayout
            android:id="@+id/input_layout_InstaReason"
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:layout_below="@+id/LLHrs"
            android:layout_marginTop="10dp"
            android:layout_weight="1">

            <android.support.design.widget.TextInputEditText
                android:id="@+id/edReworkReason"
                android:layout_width="match_parent"
                android:layout_height="wrap_content"
                android:layout_weight="1"
                android:ems="11"
                android:hint="Reason for Rework"
                android:inputType="textMultiLine"
                android:theme="@style/AutocompleteTheme" />
        </android.support.design.widget.TextInputLayout>

【讨论】:

  • 这不是问题@maheryhaja
【解决方案2】:

请检查您的 build.gradle 文件中是否添加了以下行:

compile 'com.android.support:design:27.0.2' // version is depends on your sdk download.

希望这是您的问题,如果不是,请在下面发表评论,我会帮助您解决错误。

【讨论】:

    猜你喜欢
    • 2020-11-13
    • 2017-07-21
    • 2020-06-16
    • 2016-04-05
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多