Search code examples
androidandroid-layoutandroid-viewpagerandroidx

java.lang.ClassNotFoundException: Didn't find class "androidx.core.view.ViewPager" on path


I just migrated my project to androidx and i am getting an inflation error for inflating viewpager component...I replaced android.support.v4.view.ViewPager with androidx.viewpager.widget.ViewPager

This my xml file

<FrameLayout xmlns:android="http://schemas.android.com/apk/res/android"
      android:layout_width="fill_parent"
      android:padding="@dimen/_1dp"
      android:layout_height="wrap_content"
      android:background="@color/banner_border_color">

      <androidx.viewpager.widget.ViewPager
           android:id="@+id/vp_slider"
           android:layout_width="match_parent"
           android:layout_height="@dimen/_140dp"
           android:background="@drawable/thumb_new_background" />

           <RelativeLayout
               android:layout_width="wrap_content"
               android:layout_height="wrap_content"
               android:layout_gravity="bottom">

               <TextView
                   android:id="@+id/tv_banner_view_more"
                   android:layout_width="wrap_content"
                   android:layout_height="wrap_content"
                   android:layout_centerVertical="true"
                   android:layout_marginLeft="@dimen/_16dp"
                   android:background="@drawable/drawable_btn_curved"
                   android:paddingBottom="@dimen/_6dp"
                   android:paddingLeft="@dimen/_8dp"
                   android:paddingRight="@dimen/_8dp"
                   android:paddingTop="@dimen/_6dp"
                   android:visibility="gone"
                   android:text="@string/text_view_more"
                   android:textColor="@color/c_white"
                   android:textSize="@dimen/_8sp" />

     </RelativeLayout>

</FrameLayout>

The Error i'm getting :

Caused by: android.view.InflateException: Binary XML file line #329: Binary XML file line #8: Error inflating class androidx.core.view.ViewPager
         Caused by: android.view.InflateException: Binary XML file line #8: Error inflating class androidx.core.view.ViewPager
         Caused by: java.lang.ClassNotFoundException: Didn't find class "androidx.core.view.ViewPager" on path: DexPathList[

Solution

  • You need to below dependencies in your build.gradle file

    implementation 'com.google.android.material:material:1.1.0