android.view.InflateException:二进制XML文件行#37:错误输出类EditText

时间:2016-10-14 07:03:14

标签: android android-layout gradle android-edittext inflate-exception

我正在尝试使用默认的Android模板创建登录页面。 以下是我的布局代码:

<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:tools="http://schemas.android.com/tools"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:gravity="center_horizontal"
    android:orientation="vertical"
    android:paddingBottom="@dimen/activity_vertical_margin"
    android:paddingLeft="@dimen/activity_horizontal_margin"
    android:paddingRight="@dimen/activity_horizontal_margin"
    android:paddingTop="@dimen/activity_vertical_margin"
    tools:context="com.login.app.logintest.LoginActivity">

    <!-- Login progress -->
    <ProgressBar
        android:id="@+id/login_progress"
        style="?android:attr/progressBarStyleLarge"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_marginBottom="8dp"
        android:visibility="gone" />

    <ScrollView
        android:id="@+id/login_form"
        android:layout_width="match_parent"
        android:layout_height="match_parent">

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

            <android.support.design.widget.TextInputLayout
                android:layout_width="match_parent"
                android:layout_height="wrap_content">

                <EditText
                    android:id="@+id/email"
                    android:layout_width="match_parent"
                    android:layout_height="wrap_content"
                    android:hint="@string/prompt_email"
                    android:inputType="textEmailAddress"
                    android:maxLines="1"
                    android:singleLine="true" />

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

            <android.support.design.widget.TextInputLayout
                android:layout_width="match_parent"
                android:layout_height="wrap_content">

                <EditText
                    android:id="@+id/password"
                    android:layout_width="match_parent"
                    android:layout_height="wrap_content"
                    android:hint="@string/prompt_password"
                    android:imeActionId="@+id/login"
                    android:imeActionLabel="@string/action_sign_in_short"
                    android:imeOptions="actionUnspecified"
                    android:inputType="textPassword"
                    android:maxLines="1"
                    android:singleLine="true" />

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

            <Button
                android:id="@+id/email_sign_in_button"
                style="?android:textAppearanceSmall"
                android:layout_width="match_parent"
                android:layout_height="wrap_content"
                android:layout_marginTop="16dp"
                android:text="@string/action_sign_in"
                android:textStyle="bold" />

        </LinearLayout>
    </ScrollView>
</LinearLayout>

但我在电子邮件的EditText上收到通胀异常。

    java.lang.RuntimeException: Unable to start activity ComponentInfo{com.login.app.logintest/com.login.app.logintest.LoginActivity}: android.view.InflateException: Binary XML file line #37: Error inflating class EditText
   at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2790)
   at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2855)
   at android.app.ActivityThread.access$900(ActivityThread.java:181)
   at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1474)
   at android.os.Handler.dispatchMessage(Handler.java:102)
   at android.os.Looper.loop(Looper.java:145)
   at android.app.ActivityThread.main(ActivityThread.java:6117)
   at java.lang.reflect.Method.invoke(Native Method)
   at java.lang.reflect.Method.invoke(Method.java:372)
   at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:1399)
   at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:1194)
Caused by: android.view.InflateException: Binary XML file line #37: Error inflating class EditText
   at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:770)
   at android.view.LayoutInflater.rInflate(LayoutInflater.java:813)

请建议解决方案。 仅供参考我在Android Studio中使用gradle 2.1版。

谢谢, 拉胡

2 个答案:

答案 0 :(得分:0)

而不是在xml文件中使用android:imeActionLabel,尝试将其移动到像这样的Java代码中

android:imeActionId

如果您不打算使用IME选项执行预定义操作,则最好避免使用android:imeActionLabelandroid:imeOptions <android.support.design.widget.TextInputLayout android:layout_width="match_parent" android:layout_height="wrap_content"> <android.support.v7.widget.AppCompatEditText ............ /> </android.support.design.widget.TextInputLayout> 。有关详情,请查看this link

答案 1 :(得分:0)

尝试使用 android.support.v7.widget.AppCompatEditText

dependencies {
compile 'com.android.support:appcompat-v7:23.0.1'
compile 'com.android.support:design:23.0.1'
}

确保您使用22.2.1以上的设计库,如下所示:

$accessTokenRequestUrl = $magentoUrl . 'oauth/token';
$adminAuthorizationUrl = $magentoUrl . 'admin/oauth_authorize';
$apiUrl = $magentoUrl . 'api/rest';