18

Running Android Studio 2.1.2, Windows 7.

I replaced a ScrollView with a NestedScrollView and now I'm getting

android.view.InflateException: Binary XML file line #2: Error inflating class NestedScrollView

java.lang.ClassNotFoundException: Didn't find class "android.view.NestedScrollView" on path: /data/app/com.assemblyguide.remote-48.apk

... when I call SetContentView() on that XML file. I did not get it when I had just a ScrollView.

I've tried cleaning, and invalidating the cache and rebuilding. The XML looks like this . . .

<?xml version="1.0" encoding="utf-8"?>
<NestedScrollView xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="wrap_content"
    android:layout_height="match_parent"
    android:orientation="vertical" >

    <!-- This linear layout is because the scrollview can have only 1 direct child -->
    <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:orientation="vertical" >

        <!-- Relative layout for Workorder -->
        <RelativeLayout
            android:id="@+id/rellayWorkorder"
            android:background="#383838"
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:layout_marginTop="30dp"
            android:layout_marginBottom="2dp">
            <TextView
                android:id="@+id/workorderlabel"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:layout_alignParentLeft="true"
                android:layout_margin="2dp"
                android:gravity="left"
                android:textAppearance="?android:attr/textAppearanceMedium"
                android:text="Work Order:"/>

            <TextView
                android:id="@+id/workorderContent"
                android:layout_width="150dp"
                android:layout_height="wrap_content"
                android:layout_alignParentRight="true"
                android:layout_margin="2dp"
                android:gravity="right"
                android:textAppearance="?android:attr/textAppearanceMedium"
                android:text="---workorder---"/>
        </RelativeLayout>


        <!-- Relative layout for Required Time
   <FrameLayout
       android:layout_width="match_parent"
       android:layout_height="wrap_content"
       android:layout_gravity="center_horizontal"></FrameLayout> -->

        <RelativeLayout
            android:id="@+id/rellayRequiredTime"
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:layout_marginTop="30dp"
            android:layout_marginBottom="2dp">
            <TextView
                android:id="@+id/requiredTimelabel"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:layout_alignParentLeft="true"
                android:layout_margin="2dp"
                android:gravity="left"
                android:textAppearance="?android:attr/textAppearanceMedium"
                android:text="Required Time:"/>

            <TextView
                android:id="@+id/requiredTimeContent"
                android:layout_width="150dp"
                android:layout_height="wrap_content"
                android:layout_alignParentRight="true"
                android:layout_margin="2dp"
                android:gravity="right"
                android:textAppearance="?android:attr/textAppearanceMedium"
                android:text="--- 00 minutes ---"/>
        </RelativeLayout>

        <!-- Relative layout for Time remaining -->
        <RelativeLayout
            android:id="@+id/rellayTimeRemaining"
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:layout_marginTop="30dp"
            android:layout_marginBottom="2dp">
            <TextView
                android:id="@+id/timeremaininglabel"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:layout_alignParentLeft="true"
                android:layout_margin="2dp"
                android:gravity="left"
                android:textAppearance="?android:attr/textAppearanceMedium"
                android:text="Time Remaining:"/>

            <TextView
                android:id="@+id/tviewtimeremainingContent"
                android:layout_width="150dp"
                android:layout_height="wrap_content"
                android:layout_alignParentRight="true"
                android:layout_margin="2dp"
                android:gravity="right"
                android:textAppearance="?android:attr/textAppearanceMedium"
                android:text="--- 0:00:00---"/>
        </RelativeLayout>

        <!--  Linear layout for Record Start / Record End buttons -->
        <LinearLayout
            android:orientation="horizontal"
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:layout_marginTop="10dp"  >
            <Button
                android:id="@+id/debulkrecordStart"
                android:layout_width="150dp"
                android:layout_height="wrap_content"
                android:layout_marginTop="6dp"
                android:layout_marginRight="4dp"
                android:gravity="center"
                android:textAppearance="?android:attr/textAppearanceMedium"
                android:onClick="OnSetRecordStartTimeClick"
                android:text="Record Start"/>
            <Button
                android:id="@+id/debulkrecordEnd"
                android:layout_width="150dp"
                android:layout_height="wrap_content"
                android:layout_marginTop="6dp"
                android:layout_marginRight="4dp"
                android:gravity="center"
                android:textAppearance="?android:attr/textAppearanceMedium"
                android:onClick="OnSetRecordEndTimeClick"
                android:text="Record End"/>
        </LinearLayout>

        <!-- Relative layout for Vacuum level -->
        <RelativeLayout
            android:id="@+id/rellayvacuumlevel"
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:layout_marginBottom="2dp">
            <TextView
                android:id="@+id/vaclabel"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:layout_alignParentLeft="true"
                android:layout_margin="2dp"
                android:gravity="left"
                android:textAppearance="?android:attr/textAppearanceSmall"
                android:text="Vacuum Level (inches Hg):"/>
            <EditText
                android:id="@+id/vacleveledit"
                android:layout_width="120dp"
                android:layout_height="wrap_content"
                android:layout_alignParentRight = "true"
                android:layout_margin="2dp"
                android:gravity="left"
                android:textAppearance="?android:attr/textAppearanceSmall"
                android:inputType="text|textCapCharacters"
                android:text="vac level"
                android:layout_marginRight="2dp"
                android:layout_marginTop="2dp"
                android:layout_marginBottom="2dp"/>
        </RelativeLayout>

        <!-- Relative layout for Vac Gauge Equipment # -->
        <RelativeLayout
            android:id="@+id/rlayvacuumGauge"
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:layout_marginBottom="2dp">
            <TextView
                android:id="@+id/vacgaugelabel"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:layout_alignParentLeft="true"
                android:layout_margin="2dp"
                android:gravity="left"
                android:textAppearance="?android:attr/textAppearanceSmall"
                android:text="Vac Gauge Equipment #:"/>
            <EditText
                android:id="@+id/vacgaugeedit"
                android:layout_width="120dp"
                android:layout_height="wrap_content"
                android:layout_alignParentRight = "true"
                android:layout_margin="2dp"
                android:gravity="left"
                android:textAppearance="?android:attr/textAppearanceSmall"
                android:inputType="text|textCapCharacters"
                android:text="equip. #"/>
        </RelativeLayout>



        <!-- Relative layout for Calibration Due date -->
        <RelativeLayout
            android:id="@+id/rlaycalibdue"
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:layout_marginBottom="2dp">
            <TextView
                android:id="@+id/calibduelabel"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:layout_alignParentLeft="true"
                android:layout_margin="2dp"
                android:gravity="left"
                android:textAppearance="?android:attr/textAppearanceSmall"
                android:text="Calibration Due Date:"/>
            <EditText
                android:id="@+id/calibdueedit"
                android:layout_width="120dp"
                android:layout_height="wrap_content"
                android:layout_alignParentRight = "true"
                android:layout_margin="2dp"
                android:gravity="left"
                android:textAppearance="?android:attr/textAppearanceSmall"
                android:inputType="text|textCapCharacters"
                android:text="mm/dd/yyyy"/>
        </RelativeLayout>


        <CalendarView
            android:id="@+id/debulkcalendar"
            android:layout_width="300dp"
            android:layout_height="250dp"
            android:minDate="01/01/2016"
            android:maxDate="11/30/2016"
            />


        <!--  this linear layout is for the debulk override and done buttons  -->
        <LinearLayout
            android:orientation="horizontal"
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:layout_marginTop="10dp"  >
            <Button
                android:id="@+id/debulkOverride"
                android:layout_width="150dp"
                android:layout_height="wrap_content"
                android:layout_marginTop="6dp"
                android:layout_marginRight="4dp"
                android:onClick="OnResetClick"
                android:gravity="center"
                android:textAppearance="?android:attr/textAppearanceMedium"
                android:text="Override"/>
            <Button
                android:id="@+id/debulkDone"
                android:layout_width="150dp"
                android:layout_height="wrap_content"
                android:layout_marginTop="6dp"
                android:layout_marginRight="2dp"
                android:onClick="onDoneBtnClick"
                android:gravity="center"
                android:textAppearance="?android:attr/textAppearanceMedium"
                android:text="Done"/>
        </LinearLayout>

    </LinearLayout>

</NestedScrollView>

What does this error mean and how do I fix it?

CinCout
  • 8,291
  • 9
  • 47
  • 55
user316117
  • 7,299
  • 18
  • 70
  • 141

7 Answers7

30

The full class name is android.support.v4.widget.NestedScrollView. Replace the <NestedScrollView> element with <android.support.v4.widget.NestedScrollView> and it should work fine. Make sure you have the v4 support library in your build.gradle file, too.

chessdork
  • 1,869
  • 1
  • 16
  • 20
  • 1
    Thanks, but I still don't understand: Why doesn't this flag an error in the XML at **build time**? Also, what _is_ the support library, i.e., what what's the difference between the support library and just the regular Android classes? – user316117 Jun 16 '16 at 14:14
  • 1
    The support library is a backport of certain android features that were added later. For example, the `Toolbar` widget was added in v21. This means that if you wanted to use a Toolbar in your app, your minSdk would need to be 21. There is an implementation of `android.support.v7.widget.Toolbar` that allows us to use toolbar with a minSdk of 7. In re: build time xml error, I'm not sure, but if you're using Android Studio, you can click the "Design" tab, and it will show an error. – chessdork Jun 16 '16 at 14:32
  • 3
    In latest android x, this solution won work. Try "androidx.core.widget.NestedScrollView" – Mohammed mansoor Aug 06 '19 at 09:57
26

If using androidx, replace <NestedScrollView> or full class name <android.support.v4.widget.NestedScrollView>with
<androidx.core.widget.NestedScrollView>

Claytog
  • 429
  • 4
  • 6
  • 1
    I'm using androidx and I am using `androidx.core.widget.NestedScrollView` but I still get the inflation error for some reason. – Kes Walker Jul 02 '19 at 08:11
13

Change it to

    <androidx.core.widget.NestedScrollView
        android:layout_width="match_parent"
        android:layout_height="wrap_content">
jkdev
  • 9,037
  • 14
  • 52
  • 75
7

You need to add this line in dependencies:

compile 'com.android.support:support-v4:23.4.0'

Also as chessdork said it's android.support.v4.widget.NestedScrollView not NestedScrollView

Muhammad Ashraf
  • 1,192
  • 1
  • 13
  • 31
5

when I use androidx.core.widget.NestedScrollView, I removed this line it will work fine. when I add this, app will crash (My layout also has recyclerview inside NestedScrollView)

android:nestedScrollingEnabled="false"
Hien.Nguyen
  • 76
  • 2
  • 3
  • 2
    Get similar crash related with this option. So I understand if you want make RecyclerView not scrollable you should add this line for RecyclerView, not for NestedScrollView. – SerjantArbuz Aug 17 '20 at 18:10
2

NestedScrollView was added in version 22.1.0
You should use NestedScrollView in the next way:

<?xml version="1.0" encoding="utf-8"?>
<android.support.v4.widget.NestedScrollView xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="match_parent"
    android:layout_height="match_parent">

</android.support.v4.widget.NestedScrollView>

build.gradle(module)

dependencies {
    implementation 'com.android.support:appcompat-v7:<greater than or equal to 22.1.0>'
    //...
}
yoAlex5
  • 13,571
  • 5
  • 105
  • 98
0

A silly mistake can be

android:nestedScrollingEnabled="false"

set on the NestedScrollView itself.

rahat
  • 1,489
  • 5
  • 14