无法实例化以下类: - android.support.design.widget.TextInputLayout

时间:2016-02-26 07:11:41

标签: android android-layout android-support-design

我搜索了很多。但我无法解决这个问题。

我在项目中添加了appcompatv7design库。但是我收到了这个错误。

Exception raised during rendering: com.android.layoutlib.bridge.MockView cannot be cast to android.view.ViewGroup
Exception details are logged in Window > Show View > Error Log
The following classes could not be instantiated:
- android.support.design.widget.TextInputLayout (Open Class, Show Error Log)
See the Error Log (Window > Show View) for more details.

我的xml文件是

<ScrollView
        xmlns:android="http://schemas.android.com/apk/res/android"
        android:layout_width="fill_parent"
        android:layout_height="fill_parent"
        android:fitsSystemWindows="true">

        <LinearLayout
            android:orientation="vertical"
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:paddingTop="56dp"
            android:paddingLeft="24dp"
            android:paddingRight="24dp">

            <ImageView android:src="@drawable/maitri_icon"
                android:layout_width="wrap_content"
                android:layout_height="72dp"
                android:layout_marginBottom="24dp"
                android:layout_gravity="center_horizontal" />

            <!--  Name Label -->
            <android.support.design.widget.TextInputLayout
                android:layout_width="match_parent"
                android:layout_height="wrap_content"
                android:layout_marginTop="8dp"
                android:layout_marginBottom="8dp">
                <EditText android:id="@+id/input_name"
                    android:layout_width="match_parent"
                    android:layout_height="wrap_content"
                    android:inputType="textCapWords"
                    android:hint="Name" />
            </android.support.design.widget.TextInputLayout>

            <!-- Email Label -->
            <android.support.design.widget.TextInputLayout
                android:layout_width="match_parent"
                android:layout_height="wrap_content"
                android:layout_marginTop="8dp"
                android:layout_marginBottom="8dp">
                <EditText android:id="@+id/input_email"
                    android:layout_width="match_parent"
                    android:layout_height="wrap_content"
                    android:inputType="textEmailAddress"
                    android:hint="Email" />
            </android.support.design.widget.TextInputLayout>

            <!-- Password Label -->
            <android.support.design.widget.TextInputLayout
                android:layout_width="match_parent"
                android:layout_height="wrap_content"
                android:layout_marginTop="8dp"
                android:layout_marginBottom="8dp">
                <EditText android:id="@+id/input_password"
                    android:layout_width="match_parent"
                    android:layout_height="wrap_content"
                    android:inputType="textPassword"
                    android:hint="Password"/>
            </android.support.design.widget.TextInputLayout>

            <!-- Signup Button -->
            <android.support.v7.widget.AppCompatButton
                android:id="@+id/btn_signup"
                android:layout_width="fill_parent"
                android:layout_height="wrap_content"
                android:layout_marginTop="24dp"
                android:layout_marginBottom="24dp"
                android:padding="12dp"
                android:text="Create Account"/>

            <TextView android:id="@+id/link_login"
                android:layout_width="fill_parent"
                android:layout_height="wrap_content"
                android:layout_marginBottom="24dp"
                android:text="Already a member? Login"
                android:gravity="center"
                android:textSize="16dip"/>

        </LinearLayout>
    </ScrollView>

任何答案都会对我有帮助。

2 个答案:

答案 0 :(得分:0)

将此添加到您的应用级别buid.gradle

compile 'com.android.support:design:23.1.1'

如果使用eclipse

将设计库从sdk \ extras \ android \ support \ design导入eclipse工作区,并将设计项目标记为Library by properties - &gt;选择Android - &gt;检查库

答案 1 :(得分:0)

导入设计库后,需要编辑project.properties文件,如下所示:

# Project target.
target=android-21
android.library.reference.1=../v7/appcompat
android.library=true