1

Trying to get back coding in android. Why do my program crash when I add another TextView to my XML file?

<?xml version="1.0" encoding="utf-8"?>
<android.support.v4.widget.NestedScrollView
    xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:tools="http://schemas.android.com/tools"
    xmlns:app="http://schemas.android.com/apk/res-auto"
    app:layout_behavior="@string/appbar_scrolling_view_behavior"
    tools:showIn="@layout/activity_comp_analysis"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    tools:context="com.example.oscarorellana.physicscalaculators.Math.CompAnalysis">


        <TextView
        android:layout_width="match_parent"
        android:layout_height="50dp"
        android:text="Enter a complex number below"
        android:textSize="20dp"
        android:textStyle="bold"
        />

        <TextView
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:text="TEST"
            />
</android.support.v4.widget.NestedScrollView>

The XML file is my content file in one of my Android Activities. Probably really basic, but I can't find the mistake.

PEHLAJ
  • 9,980
  • 9
  • 41
  • 53

3 Answers3

1

NestedScrollView should have only one direct child. Add a new Linear/Relative layout as a container or TextViews.

Try this:

<NestedScrollView>
    <LinearLayout>
         <TextView>
         <TextView>
    <LinearLayout>
<NestedScrollView>

Update your XML as below:

<?xml version="1.0" encoding="utf-8"?>
<android.support.v4.widget.NestedScrollView
    xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:tools="http://schemas.android.com/tools"
    xmlns:app="http://schemas.android.com/apk/res-auto"
    app:layout_behavior="@string/appbar_scrolling_view_behavior"
    tools:showIn="@layout/activity_comp_analysis"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    tools:context="com.example.oscarorellana.physicscalaculators.Math.CompAnalysis">

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

        <TextView
            android:layout_width="match_parent"
            android:layout_height="50dp"
            android:text="Enter a complex number below"
            android:textSize="20dp"
            android:textStyle="bold" />

        <TextView
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:text="TEST" />
    </LinearLayout>

</android.support.v4.widget.NestedScrollView>
Ferdous Ahamed
  • 21,438
  • 5
  • 52
  • 61
1

Try this code : You need to add child under the scroll view , Then only the scroll view will work:

<?xml version="1.0" encoding="utf-8"?>
    <android.support.v4.widget.NestedScrollView xmlns:android="http://schemas.android.com/apk/res/android"
        xmlns:app="http://schemas.android.com/apk/res-auto"
        xmlns:tools="http://schemas.android.com/tools"
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        app:layout_behavior="@string/appbar_scrolling_view_behavior"
        tools:context="com.example.oscarorellana.physicscalaculators.Math.CompAnalysis"
        tools:showIn="@layout/activity_comp_analysis">

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

            <TextView
                android:layout_width="match_parent"
                android:layout_height="50dp"
                android:text="Enter a complex number below"
                android:textSize="20dp"
                android:textStyle="bold" />

            <TextView
                android:layout_width="match_parent"
                android:layout_height="wrap_content"
                android:text="TEST" />
        </LinearLayout>
    </android.support.v4.widget.NestedScrollView>
Ajay Venugopal
  • 1,544
  • 1
  • 17
  • 30
0
<?xml version="1.0" encoding="utf-8"?>
<android.support.v4.widget.NestedScrollView
    xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:tools="http://schemas.android.com/tools"
    xmlns:app="http://schemas.android.com/apk/res-auto"
    app:layout_behavior="@string/appbar_scrolling_view_behavior"
    tools:showIn="@layout/activity_comp_analysis"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    tools:context="com.example.oscarorellana.physicscalaculators.Math.CompAnalysis">

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


        <TextView
        android:layout_width="match_parent"
        android:layout_height="50dp"
        android:text="Enter a complex number below"
        android:textSize="20dp"
        android:textStyle="bold"
        />

        <TextView
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:text="TEST"
            />

    </LinearLayout>
</android.support.v4.widget.NestedScrollView>
PEHLAJ
  • 9,980
  • 9
  • 41
  • 53