膨胀 class 时出错 - NestedScrollView - class 未找到
Error inflating class - NestedScrollView - class not found
运行 Android Studio 2.1.2,Windows 7.
我用 NestedScrollView 替换了 ScrollView,现在
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
...当我在 XML 文件上调用 SetContentView() 时。我只有一个ScrollView的时候没搞定
我试过清理、使缓存失效并重建。 XML 看起来像这样。 . .
<?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>
这个错误是什么意思,我该如何解决?
完整的 class 名称是 android.support.v4.widget.NestedScrollView
。用 <android.support.v4.widget.NestedScrollView>
替换 <NestedScrollView>
元素,它应该可以正常工作。确保你的 build.gradle 文件中也有 v4 支持库。
您需要在依赖项中添加这一行:
compile 'com.android.support:support-v4:23.4.0'
正如 chessdork 所说,它是 android.support.v4.widget.NestedScrollView
而不是 NestedScrollView
NestedScrollView was added in version 22.1.0
您应该按以下方式使用 NestedScrollView:
<?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(模块)
dependencies {
implementation 'com.android.support:appcompat-v7:<greater than or equal to 22.1.0>'
//...
}
如果使用 androidx,请将 <NestedScrollView>
或完整的 class 名称 <android.support.v4.widget.NestedScrollView>
替换为
<androidx.core.widget.NestedScrollView>
改为
<androidx.core.widget.NestedScrollView
android:layout_width="match_parent"
android:layout_height="wrap_content">
当我使用 androidx.core.widget.NestedScrollView 时,我删除了这行它会正常工作。当我添加这个时,应用程序会崩溃(我的布局在 NestedScrollView 中也有 recyclerview)
android:nestedScrollingEnabled="false"
一个愚蠢的错误可能是
android:nestedScrollingEnabled="false"
在 NestedScrollView 本身上设置。
运行 Android Studio 2.1.2,Windows 7.
我用 NestedScrollView 替换了 ScrollView,现在
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
...当我在 XML 文件上调用 SetContentView() 时。我只有一个ScrollView的时候没搞定
我试过清理、使缓存失效并重建。 XML 看起来像这样。 . .
<?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>
这个错误是什么意思,我该如何解决?
完整的 class 名称是 android.support.v4.widget.NestedScrollView
。用 <android.support.v4.widget.NestedScrollView>
替换 <NestedScrollView>
元素,它应该可以正常工作。确保你的 build.gradle 文件中也有 v4 支持库。
您需要在依赖项中添加这一行:
compile 'com.android.support:support-v4:23.4.0'
正如 chessdork 所说,它是 android.support.v4.widget.NestedScrollView
而不是 NestedScrollView
NestedScrollView was added in version 22.1.0
您应该按以下方式使用 NestedScrollView:
<?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(模块)
dependencies {
implementation 'com.android.support:appcompat-v7:<greater than or equal to 22.1.0>'
//...
}
如果使用 androidx,请将 <NestedScrollView>
或完整的 class 名称 <android.support.v4.widget.NestedScrollView>
替换为 <androidx.core.widget.NestedScrollView>
改为
<androidx.core.widget.NestedScrollView
android:layout_width="match_parent"
android:layout_height="wrap_content">
当我使用 androidx.core.widget.NestedScrollView 时,我删除了这行它会正常工作。当我添加这个时,应用程序会崩溃(我的布局在 NestedScrollView 中也有 recyclerview)
android:nestedScrollingEnabled="false"
一个愚蠢的错误可能是
android:nestedScrollingEnabled="false"
在 NestedScrollView 本身上设置。