0

My application getting crash by throughing below errors for scrollview, even childs are grouped in parent view. this is happening only when internet is off, otherwise it's working.

02-22 14:26:20.504 13277-13277/com.eonelectric.eon E/AndroidRuntime: FATAL EXCEPTION: main
                                                                 Process: com.eonelectric.eon, PID: 13277
                                                                 java.lang.IllegalStateException: ScrollView can host only one direct child
                                                                     at android.widget.ScrollView.addView(ScrollView.java:248)
                                                                     at android.support.design.widget.Snackbar.showView(Snackbar.java:483)
                                                                     at android.support.design.widget.Snackbar$1.handleMessage(Snackbar.java:167)
                                                                     at android.os.Handler.dispatchMessage(Handler.java:98)
                                                                     at android.os.Looper.loop(Looper.java:135)
                                                                     at android.app.ActivityThread.main(ActivityThread.java:5343)
                                                                     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:905)
                                                                     at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:700)

My layout file is here.

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

<FrameLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:id="@+id/main_layout"
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:orientation="vertical">

    <ImageView
        android:id="@+id/loginBackgroundIv"
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:scaleType="fitXY"
        android:src="@drawable/login_bg"
        tools:ignore="ContentDescription"/>

    <de.hdodenhof.circleimageview.CircleImageView xmlns:app="http://schemas.android.com/apk/res-auto"
        android:id="@+id/profilePicIv"
        android:layout_width="135dp"
        android:layout_height="110dp"
        android:layout_gravity="center_horizontal"
        android:layout_marginTop="16dp"
        android:scaleType="centerCrop"
        android:src="@drawable/user"
        app:civ_border_color="#fff"
        app:civ_border_width="2dp" />

    <LinearLayout
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:layout_marginBottom="16dp"
        android:layout_marginLeft="16dp"
        android:layout_marginRight="16dp"
        android:layout_marginTop="130dp"
        android:orientation="vertical">

        <android.support.design.widget.TextInputLayout
            android:id="@+id/nameWraper"
            android:layout_width="match_parent"
            android:layout_height="wrap_content">

            <android.support.design.widget.TextInputEditText
                android:id="@+id/nameEt"
                style="@style/custom_et"
                android:layout_width="match_parent"
                android:layout_height="wrap_content"
                android:inputType="textPersonName"
                android:singleLine="true"
                android:textColor="#ffffff" />
        </android.support.design.widget.TextInputLayout>

        <android.support.design.widget.TextInputLayout
            android:id="@+id/phoneWrapper"
            android:layout_width="match_parent"
            android:layout_height="wrap_content">

            <android.support.design.widget.TextInputEditText
                android:id="@+id/phoneEt"
                style="@style/custom_et"
                android:layout_width="match_parent"
                android:layout_height="wrap_content"
                android:inputType="number"
                android:maxLength="10"
                android:singleLine="true" />
        </android.support.design.widget.TextInputLayout>

        <android.support.design.widget.TextInputLayout
            android:id="@+id/emailWrapper"
            android:layout_width="match_parent"
            android:layout_height="wrap_content">

            <android.support.design.widget.TextInputEditText
                android:id="@+id/emailEt"
                style="@style/custom_et"
                android:layout_width="match_parent"
                android:layout_height="wrap_content"
                android:singleLine="true" />
        </android.support.design.widget.TextInputLayout>

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

            <android.support.design.widget.TextInputLayout
                android:id="@+id/pwdwrapper"
                android:layout_width="match_parent"
                android:layout_height="wrap_content">

                <android.support.design.widget.TextInputEditText
                    android:id="@+id/pwdEt"
                    style="@style/custom_et"
                    android:layout_width="match_parent"
                    android:layout_height="wrap_content"
                    android:inputType="textWebPassword"
                    android:singleLine="true" />
            </android.support.design.widget.TextInputLayout>

            <android.support.design.widget.TextInputLayout
                android:id="@+id/repwdwrapper"
                android:layout_width="match_parent"
                android:layout_height="wrap_content">

                <android.support.design.widget.TextInputEditText
                    android:id="@+id/repwdEt"
                    style="@style/custom_et"
                    android:layout_width="match_parent"
                    android:layout_height="wrap_content"
                    android:inputType="textWebPassword"
                    android:singleLine="true" />
            </android.support.design.widget.TextInputLayout>
        </LinearLayout>

        <!--<LinearLayout
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:gravity="center_vertical"
            android:orientation="horizontal"
            android:weightSum="100">

            <TextView
                android:layout_width="0dp"
                android:layout_height="wrap_content"
                android:layout_weight="40"
                android:padding="8dp"
                android:text="User type ?"
                android:textColor="@android:color/white"
                android:textSize="16sp" />

            <Spinner
                android:id="@+id/userTypeSpinner"
                android:layout_width="0dp"
                android:layout_height="wrap_content"
                android:layout_weight="60"
                android:entries="@array/userTypeArray" />
        </LinearLayout>-->

        <LinearLayout
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:gravity="center_vertical"
            android:orientation="horizontal"
            android:weightSum="100">

            <TextView
                android:layout_width="0dp"
                android:layout_height="wrap_content"
                android:layout_weight="40"
                android:padding="8dp"
                android:text="State ?"
                android:textColor="@android:color/white"
                android:textSize="16sp" />

            <Spinner
                android:id="@+id/stateSpinner"
                android:layout_width="0dp"
                android:layout_height="wrap_content"
                android:layout_weight="60" />
        </LinearLayout>

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

            <android.support.design.widget.TextInputLayout
                android:id="@+id/empCodeWrapper"
                android:layout_width="match_parent"
                android:layout_height="wrap_content">

                <android.support.design.widget.TextInputEditText
                    android:id="@+id/empCodeEt"
                    style="@style/custom_et"
                    android:layout_width="match_parent"
                    android:layout_height="wrap_content"
                    android:singleLine="true" />
            </android.support.design.widget.TextInputLayout>

            <!--<android.support.design.widget.TextInputLayout
                android:id="@+id/empDivCodeWrapper"
                android:layout_width="match_parent"
                android:layout_height="wrap_content">

                <EditText
                    android:id="@+id/empDivCodeEt"
                    style="@style/custom_et"
                    android:layout_width="match_parent"
                    android:layout_height="wrap_content"
                    android:singleLine="true" />
            </android.support.design.widget.TextInputLayout>-->
        </LinearLayout>

        <Button
            android:id="@+id/finishSignupBtn"
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:layout_marginTop="16dp"
            android:text="Sign Up"
            android:textColor="@android:color/white" />
    </LinearLayout>

</FrameLayout>
</ScrollView>
Jaap
  • 81,064
  • 34
  • 182
  • 193
Ashish Patel
  • 304
  • 1
  • 3
  • 11
  • Please share activity code – Farhan Munir Feb 22 '17 at 09:53
  • Like the error says. You need to wrap child layout in linear layouts and run – rohitanand Feb 24 '17 at 12:27
  • Possible duplicate of [How can I avoid "IllegalStateException: Scrollview can host only one direct child"?](http://stackoverflow.com/questions/3735095/how-can-i-avoid-illegalstateexception-scrollview-can-host-only-one-direct-chil) – rohitanand Feb 24 '17 at 12:28

2 Answers2

1
       <?xml version="1.0" encoding="utf-8"?>
 <RelativeLayout android:layout_width="match_parent"
android:layout_height="match_parent"
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools">
<ScrollView
android:layout_width="match_parent"
android:layout_height="match_parent"
android:fillViewport="true">

<FrameLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:id="@+id/main_layout"
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:orientation="vertical">

    <ImageView
        android:id="@+id/loginBackgroundIv"
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:scaleType="fitXY"
        tools:ignore="ContentDescription"/>

    <de.hdodenhof.circleimageview.CircleImageView xmlns:app="http://schemas.android.com/apk/res-auto"
        android:id="@+id/profilePicIv"
        android:layout_width="135dp"
        android:layout_height="110dp"
        android:layout_gravity="center_horizontal"
        android:layout_marginTop="16dp"
        android:scaleType="centerCrop"
        app:civ_border_color="#fff"
        app:civ_border_width="2dp" />

    <LinearLayout
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:layout_marginBottom="16dp"
        android:layout_marginLeft="16dp"
        android:layout_marginRight="16dp"
        android:layout_marginTop="130dp"
        android:orientation="vertical">

        <android.support.design.widget.TextInputLayout
            android:id="@+id/nameWraper"
            android:layout_width="match_parent"
            android:layout_height="wrap_content">

            <android.support.design.widget.TextInputEditText
                android:id="@+id/nameEt"
                android:layout_width="match_parent"
                android:layout_height="wrap_content"
                android:inputType="textPersonName"
                android:singleLine="true"
                android:textColor="#ffffff" />
        </android.support.design.widget.TextInputLayout>

        <android.support.design.widget.TextInputLayout
            android:id="@+id/phoneWrapper"
            android:layout_width="match_parent"
            android:layout_height="wrap_content">

            <android.support.design.widget.TextInputEditText
                android:id="@+id/phoneEt"
                android:layout_width="match_parent"
                android:layout_height="wrap_content"
                android:inputType="number"
                android:maxLength="10"
                android:singleLine="true" />
        </android.support.design.widget.TextInputLayout>

        <android.support.design.widget.TextInputLayout
            android:id="@+id/emailWrapper"
            android:layout_width="match_parent"
            android:layout_height="wrap_content">

            <android.support.design.widget.TextInputEditText
                android:id="@+id/emailEt"
                android:layout_width="match_parent"
                android:layout_height="wrap_content"
                android:singleLine="true" />
        </android.support.design.widget.TextInputLayout>

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

            <android.support.design.widget.TextInputLayout
                android:id="@+id/pwdwrapper"
                android:layout_width="match_parent"
                android:layout_height="wrap_content">

                <android.support.design.widget.TextInputEditText
                    android:id="@+id/pwdEt"
                    android:layout_width="match_parent"
                    android:layout_height="wrap_content"
                    android:inputType="textWebPassword"
                    android:singleLine="true" />
            </android.support.design.widget.TextInputLayout>

            <android.support.design.widget.TextInputLayout
                android:id="@+id/repwdwrapper"
                android:layout_width="match_parent"
                android:layout_height="wrap_content">

                <android.support.design.widget.TextInputEditText
                    android:id="@+id/repwdEt"

                    android:layout_width="match_parent"
                    android:layout_height="wrap_content"
                    android:inputType="textWebPassword"
                    android:singleLine="true" />
            </android.support.design.widget.TextInputLayout>
        </LinearLayout>

        <!--<LinearLayout
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:gravity="center_vertical"
            android:orientation="horizontal"
            android:weightSum="100">

            <TextView
                android:layout_width="0dp"
                android:layout_height="wrap_content"
                android:layout_weight="40"
                android:padding="8dp"
                android:text="User type ?"
                android:textColor="@android:color/white"
                android:textSize="16sp" />

            <Spinner
                android:id="@+id/userTypeSpinner"
                android:layout_width="0dp"
                android:layout_height="wrap_content"
                android:layout_weight="60"
                android:entries="@array/userTypeArray" />
        </LinearLayout>-->

        <LinearLayout
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:gravity="center_vertical"
            android:orientation="horizontal"
            android:weightSum="100">

            <TextView
                android:layout_width="0dp"
                android:layout_height="wrap_content"
                android:layout_weight="40"
                android:padding="8dp"
                android:text="State ?"
                android:textColor="@android:color/white"
                android:textSize="16sp" />

            <Spinner
                android:id="@+id/stateSpinner"
                android:layout_width="0dp"
                android:layout_height="wrap_content"
                android:layout_weight="60" />
        </LinearLayout>

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

            <android.support.design.widget.TextInputLayout
                android:id="@+id/empCodeWrapper"
                android:layout_width="match_parent"
                android:layout_height="wrap_content">

                <android.support.design.widget.TextInputEditText
                    android:id="@+id/empCodeEt"
                    android:layout_width="match_parent"
                    android:layout_height="wrap_content"
                    android:singleLine="true" />
            </android.support.design.widget.TextInputLayout>

            <!--<android.support.design.widget.TextInputLayout
                android:id="@+id/empDivCodeWrapper"
                android:layout_width="match_parent"
                android:layout_height="wrap_content">

                <EditText
                    android:id="@+id/empDivCodeEt"
                    style="@style/custom_et"
                    android:layout_width="match_parent"
                    android:layout_height="wrap_content"
                    android:singleLine="true" />
            </android.support.design.widget.TextInputLayout>-->
        </LinearLayout>

        <Button
            android:id="@+id/finishSignupBtn"
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:layout_marginTop="16dp"
            android:text="Sign Up"
            android:textColor="@android:color/white" />
    </LinearLayout>

</FrameLayout>

Maitri
  • 513
  • 1
  • 3
  • 14
0

ScrollView can have only one child view. Make a LinearLayout inside ScrollView to wrap all of child view. Like -

<?xml version="1.0" encoding="utf-8"?>
<FrameLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:id="@+id/main_layout"
    android:layout_width="match_parent"
    android:layout_height="match_parent">


   <ScrollView 
         android:layout_width="match_parent"
         android:layout_height="match_parent"
         xmlns:tools="http://schemas.android.com/tools"
         android:fillViewport="true">

   <LinearLayout
         android:layout_width="match_parent"
         android:layout_height="match_parent"
         android:orientation="vertical">


    <ImageView
        android:id="@+id/loginBackgroundIv"
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:scaleType="fitXY"
        android:src="@drawable/login_bg"
        tools:ignore="ContentDescription"/>

    <de.hdodenhof.circleimageview.CircleImageView xmlns:app="http://schemas.android.com/apk/res-auto"
        android:id="@+id/profilePicIv"
        android:layout_width="135dp"
        android:layout_height="110dp"
        android:layout_gravity="center_horizontal"
        android:layout_marginTop="16dp"
        android:scaleType="centerCrop"
        android:src="@drawable/user"
        app:civ_border_color="#fff"
        app:civ_border_width="2dp" />

    <LinearLayout
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:layout_marginBottom="16dp"
        android:layout_marginLeft="16dp"
        android:layout_marginRight="16dp"
        android:layout_marginTop="130dp"
        android:orientation="vertical">

        <android.support.design.widget.TextInputLayout
            android:id="@+id/nameWraper"
            android:layout_width="match_parent"
            android:layout_height="wrap_content">

            <android.support.design.widget.TextInputEditText
                android:id="@+id/nameEt"
                style="@style/custom_et"
                android:layout_width="match_parent"
                android:layout_height="wrap_content"
                android:inputType="textPersonName"
                android:singleLine="true"
                android:textColor="#ffffff" />
        </android.support.design.widget.TextInputLayout>

        <android.support.design.widget.TextInputLayout
            android:id="@+id/phoneWrapper"
            android:layout_width="match_parent"
            android:layout_height="wrap_content">

            <android.support.design.widget.TextInputEditText
                android:id="@+id/phoneEt"
                style="@style/custom_et"
                android:layout_width="match_parent"
                android:layout_height="wrap_content"
                android:inputType="number"
                android:maxLength="10"
                android:singleLine="true" />
        </android.support.design.widget.TextInputLayout>

        <android.support.design.widget.TextInputLayout
            android:id="@+id/emailWrapper"
            android:layout_width="match_parent"
            android:layout_height="wrap_content">

            <android.support.design.widget.TextInputEditText
                android:id="@+id/emailEt"
                style="@style/custom_et"
                android:layout_width="match_parent"
                android:layout_height="wrap_content"
                android:singleLine="true" />
        </android.support.design.widget.TextInputLayout>

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

            <android.support.design.widget.TextInputLayout
                android:id="@+id/pwdwrapper"
                android:layout_width="match_parent"
                android:layout_height="wrap_content">

                <android.support.design.widget.TextInputEditText
                    android:id="@+id/pwdEt"
                    style="@style/custom_et"
                    android:layout_width="match_parent"
                    android:layout_height="wrap_content"
                    android:inputType="textWebPassword"
                    android:singleLine="true" />
            </android.support.design.widget.TextInputLayout>

            <android.support.design.widget.TextInputLayout
                android:id="@+id/repwdwrapper"
                android:layout_width="match_parent"
                android:layout_height="wrap_content">

                <android.support.design.widget.TextInputEditText
                    android:id="@+id/repwdEt"
                    style="@style/custom_et"
                    android:layout_width="match_parent"
                    android:layout_height="wrap_content"
                    android:inputType="textWebPassword"
                    android:singleLine="true" />
            </android.support.design.widget.TextInputLayout>
        </LinearLayout>

        <!--<LinearLayout
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:gravity="center_vertical"
            android:orientation="horizontal"
            android:weightSum="100">

            <TextView
                android:layout_width="0dp"
                android:layout_height="wrap_content"
                android:layout_weight="40"
                android:padding="8dp"
                android:text="User type ?"
                android:textColor="@android:color/white"
                android:textSize="16sp" />

            <Spinner
                android:id="@+id/userTypeSpinner"
                android:layout_width="0dp"
                android:layout_height="wrap_content"
                android:layout_weight="60"
                android:entries="@array/userTypeArray" />
        </LinearLayout>-->

        <LinearLayout
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:gravity="center_vertical"
            android:orientation="horizontal"
            android:weightSum="100">

            <TextView
                android:layout_width="0dp"
                android:layout_height="wrap_content"
                android:layout_weight="40"
                android:padding="8dp"
                android:text="State ?"
                android:textColor="@android:color/white"
                android:textSize="16sp" />

            <Spinner
                android:id="@+id/stateSpinner"
                android:layout_width="0dp"
                android:layout_height="wrap_content"
                android:layout_weight="60" />
        </LinearLayout>

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

            <android.support.design.widget.TextInputLayout
                android:id="@+id/empCodeWrapper"
                android:layout_width="match_parent"
                android:layout_height="wrap_content">

                <android.support.design.widget.TextInputEditText
                    android:id="@+id/empCodeEt"
                    style="@style/custom_et"
                    android:layout_width="match_parent"
                    android:layout_height="wrap_content"
                    android:singleLine="true" />
            </android.support.design.widget.TextInputLayout>

            <!--<android.support.design.widget.TextInputLayout
                android:id="@+id/empDivCodeWrapper"
                android:layout_width="match_parent"
                android:layout_height="wrap_content">

                <EditText
                    android:id="@+id/empDivCodeEt"
                    style="@style/custom_et"
                    android:layout_width="match_parent"
                    android:layout_height="wrap_content"
                    android:singleLine="true" />
            </android.support.design.widget.TextInputLayout>-->
        </LinearLayout>

        <Button
            android:id="@+id/finishSignupBtn"
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:layout_marginTop="16dp"
            android:text="Sign Up"
            android:textColor="@android:color/white" />
    </LinearLayout>

</LinearLayout>

</ScrollView>
</FrameLayout>
AGM Tazim
  • 2,213
  • 3
  • 16
  • 25