充气时的ClassNotFoundException重新android.support.v4.view.ViewPager

安迪:

我增加了ViewPager到我的Android Studio中的应用程序,但是当我尝试运行它,它抛出一个ClassNotFoundException重类“android.support.v4.view.ViewPager”。

已经做了很多谷歌搜索,并试图在的build.gradle改变依赖,但一切都没有改变,我看到的错误。

以下是logcat的相关错误行:

java.lang.RuntimeException: Unable to start activity ComponentInfo{com.example.android.playmusic/com.example.android.playmusic.MainActivity}: android.view.InflateException: Binary XML file line #60: Binary XML file line #60: Error inflating class android.support.v4.view.ViewPager
...
Caused by: android.view.InflateException: Binary XML file line #60: Binary XML file line #60: Error inflating class android.support.v4.view.ViewPager
Caused by: android.view.InflateException: Binary XML file line #60: Error inflating class android.support.v4.view.ViewPager
Caused by: java.lang.ClassNotFoundException: Didn't find class "android.support.v4.view.ViewPager" on path: DexPathList[[zip file "/data/app/com.example.android.playmusic--Sh7PlYKQR0g2meRQdvXcg==/base.apk"],nativeLibraryDirectories=[/data/app/com.example.android.playmusic--Sh7PlYKQR0g2meRQdvXcg==/lib/arm64, /system/lib64, /system/vendor/lib64]]

这里是main_activity.xml布局:

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

    <androidx.appcompat.widget.Toolbar
        android:id="@+id/my_toolbar"
        android:layout_width="match_parent"
        android:layout_height="?attr/actionBarSize"
        android:background="?attr/colorPrimary"
        android:elevation="4dp"
        android:theme="@style/ThemeOverlay.AppCompat.ActionBar"
        app:popupTheme="@style/ThemeOverlay.AppCompat.Light"/>

    <com.google.android.material.tabs.TabLayout
        android:id="@+id/main_tabs"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_marginStart="8dp"
        android:layout_marginTop="8dp"
        android:layout_marginEnd="8dp"
        app:tabMode="scrollable">

        <com.google.android.material.tabs.TabItem
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:text="@string/tab0" />

        <com.google.android.material.tabs.TabItem
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:text="@string/tab1" />

        <com.google.android.material.tabs.TabItem
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:text="@string/tab2" />

    </com.google.android.material.tabs.TabLayout>

    <!-- View pager to swipe views -->
    <android.support.v4.view.ViewPager
        android:id="@+id/pager"
        android:layout_width="match_parent"
        android:layout_height="fill_parent"/>

</LinearLayout>

下面是我在的build.gradle依赖性。正如你可以看到我已经使用这两种androidx和viewpager制造品的com.android.support版本的尝试:

dependencies {
    implementation fileTree(dir: 'libs', include: ['*.jar'])
    implementation 'com.android.support:appcompat-v7:28.0.0'
    implementation "com.android.support:design:28.0.0"
    implementation 'com.android.support.constraint:constraint-layout:1.1.3'
    testImplementation 'junit:junit:4.12'
    androidTestImplementation 'com.android.support.test:runner:1.0.2'
    androidTestImplementation 'com.android.support.test.espresso:espresso-core:3.0.2'
    implementation 'androidx.recyclerview:recyclerview:1.0.0'
    implementation 'com.loopj.android:android-async-http:1.4.9'
    implementation "android.arch.lifecycle:extensions:1.1.0"
    implementation "android.arch.lifecycle:viewmodel:1.1.0"
    //implementation "androidx.viewpager:viewpager:1.0.0"
    implementation "com.android.support:viewpager:28.0.0"
}

任何帮助将是非常欢迎的。

基肖尔Jethava:

如果您正在使用 implementation "androidx.viewpager:viewpager:1.0.0"

此外,在XML文件中也可能发生变化

<androidx.viewpager.widget.ViewPager
    android:id="@+id/pager"
    android:layout_width="match_parent"
    android:layout_height="fill_parent"/>

本文收集自互联网,转载请注明来源。

如有侵权,请联系 [email protected] 删除。

编辑于
0

我来说两句

0 条评论
登录 后参与评论

相关文章

setupWithViewPager(android.support.v4.view.ViewPager)在TabLayout不能BR施加到(androidx.viewpager..widget.ViewPager)

java.lang.ClassNotFoundException:android.support.v4.view.TintableBackgroundView

NoClassDefFoundError:android.support.v7.internal.view.menu.MenuBuilder

使用ViewPager的Android.app片段与android.support.v4.app?

java.lang.NoClassDefFoundError:Android Studio中的android.support.v4.view.LayoutInflaterCompatHC

RecyclerView ViewPager java.lang.NullPointerException android.support.v7.widget.RecyclerView $ ItemAnimator $ ItemHolderInfo.left

android.support.v7.view.menu.ActionMenuItemView无法转换为android.widget.Button

java.lang.NoSuchMethodError:类Landroid / support / v4 / view / KeyEventCompatHoneycomb中没有静态方法isCtrlPressed(Landroid / view / KeyEvent;)Z

TransformException:java.util.zip.ZipException:重复项:android / support / v4 / content / res / TypedArrayUtils.class

NoClassDefFoundError android / support / v4 / animation / AnimatorCompatHelper

重复的zip条目[classes.jar:android / support / v4 / media / MediaBrowserCompat $ MediaItem $ 1.class]

二进制XML文件第18行:膨胀类android.support.v4.widget.view.ViewPager时出错

找不到support-v4.aar(com.android.support:support-v4:26.1.0)

错误:程序包android.support.v4.view不存在

为什么可以在Android 4.0.3模拟器上使用Android Support v4

我需要将线性布局放置在v4.view.ViewPager上

RuntimeException:膨胀类android.suppoort.v4.view.ViewPager时出错

如何修复Tab中的android.support.v4.view.pageTitleStrip?

无法在android 4.4.2中使用此“ android.support.v4.view.ViewPager”进行构建

子模块目录中的Android Support V4断开链接

多个dex文件定义了Landroid / support / v4 /

android.view.InflateException:膨胀类android.support.v7.widget.CardView时出错

尝试在空对象引用上调用虚拟方法'void android.support.v4.view.ViewPager.setAdapter(android.support.v4.view.PagerAdapter)'

android.support.v7.internal.view.menu.ActionMenuItemView无法转换为android.widget.Button

android.view.inflaterexception二进制xml文件第6行错误,膨胀类support.v4.view.ViewPager

Android-重复条目:android / support / v4 / database / DatabaseUtilsCompat.class?

android.support.v4库错误

ViewPager 上的 findViewById 返回“Android.view.View”,无法转换为 ViewPager

android.support.v7.widget.AppCompatImageView 不能投射到 android.view.ViewGroup