My XML code keeps crashing my app, what is wrong with it?

Advertisements

I dont know what wrong with it but it’s just crashing my app, if you need i will post my java code later cause stack isnt letting me to do it now.When i comment EditTexts it working fine but not as needed so i believe something is wrong with it

<?xml version="1.0" encoding="utf-8"?>
<androidx.core.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"
    tools:context=".MainActivity">

        <EditText
            android:id="@+id/A"
            android:layout_height="wrap_content"
            android:layout_width="match_parent"
            android:inputType="number"/>

        <EditText
            android:id="@+id/B"
            android:layout_height="wrap_content"
            android:layout_width="match_parent"
            android:inputType="number"/>
        <EditText
            android:id="@+id/C"
            android:layout_height="wrap_content"
            android:layout_width="match_parent"
            android:inputType="number"/>
        <Button
            android:layout_width="match_parent"
            android:layout_height="match_parent"
            android:id="@+id/calculate"
            android:text="calculate"
            />
        <TextView
            android:layout_width="match_parent"
            android:layout_height="match_parent"
            android:id="@+id/output"
            />


</androidx.core.widget.NestedScrollView>

>Solution :

(Nested)ScrollView can have only one direct child. Basically, ScrollView takes care of scrolling but needs just one element to scroll.

<?xml version="1.0" encoding="utf-8"?>
<androidx.core.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"
    tools:context=".MainActivity">

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

        <EditText
            android:id="@+id/A"
            android:layout_height="wrap_content"
            android:layout_width="match_parent"
            android:inputType="number"/>
        <EditText
            android:id="@+id/B"
            android:layout_height="wrap_content"
            android:layout_width="match_parent"
            android:inputType="number"/>
        <EditText
            android:id="@+id/C"
            android:layout_height="wrap_content"
            android:layout_width="match_parent"
            android:inputType="number"/>
        <Button
            android:layout_width="wrap_content"
            android:layout_height="match_parent"
            android:id="@+id/calculate"
            android:text="calculate" />
        <TextView
            android:layout_width="wrap_content"
            android:layout_height="match_parent"
            android:id="@+id/output" />

    </LinearLayout >

</androidx.core.widget.NestedScrollView>

Leave a ReplyCancel reply