0

Trying to learn Android development. I am using Android Studio 2.1.3 and tried to create a login feature. Made use of Login Activity template while creating the project and left everything else in the wizard to be default. When I tried to preview what exactly it has created it shows this error.

The following classes could not be instantiated: android.support.design.widget.TextInputLayout

By default the android version to target was showing as 24 I changed it to 15 but still the same error. How to solve this?

enter image description here

Layout xml

<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.example.user.loginapp.Login">

    <!-- 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">

                <AutoCompleteTextView
                    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>
prasanth
  • 483
  • 1
  • 4
  • 11
  • Can you please provide the XML for the layout file you are using? – Chad Schultz Sep 09 '16 at 18:28
  • Also, try the answers at http://stackoverflow.com/questions/26575815/the-following-classes-could-not-be-instantiated-android-support-v7-widget-too and see if one of them works for you. – Chad Schultz Sep 09 '16 at 18:29
  • @ChadSchultz I have updated the question with layout xml now. Also I have tried to Invalidate Caches / Restart it didn't solve the problem. Also I tried changing the android version from 24 to 15 it too didn't solve the problem – prasanth Sep 09 '16 at 18:39
  • The good news: the problem happens for me too! It's not just your. The bad news: I haven't found a way to fix it. There are a number of discussions: http://stackoverflow.com/questions/30570569/rendering-problems-using-new-textinputlayout-for-edittext http://stackoverflow.com/questions/26575815/the-following-classes-could-not-be-instantiated-android-support-v7-widget-too and more, but none worked for me. The visual editor is just super buggy. Hope Google fixes it someday! This is why I always just test layouts on the device. – Chad Schultz Sep 09 '16 at 19:03

1 Answers1

0

You can either use appcompat by adding compile 'com.android.support:appcompat-v7:xxx to your gradle or change your minsdk in your gradle to 21 or above (lolipop is the first one to support Material Design).

Read Documention here

to learn more about maintaining backward compatibility.

user6657161
  • 361
  • 1
  • 8