42

I'm trying to use RecyclerView in my existing project, builds without errors but getting no class found error for the RecyclerView while inflating. Cannot see what I'm doing wrong. Thanks for helping!

//activity_main.xml

<LinearLayout
    xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_height="match_parent"
    android:layout_width="match_parent"
    android:orientation="vertical">

    <android.support.v7.widget.RecyclerView
        android:id="@+id/recyclerView"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"/>
</LinearLayout>

//MainActivity.onCreate
    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);
        recyclerView = (RecyclerView) findViewById(R.id.recyclerView);
        ItemData itemsData[] = { new ItemData("Help",R.drawable.visa),
                new ItemData("Delete",R.drawable.sample),
                new ItemData("Cloud",R.drawable.sample),
                new ItemData("Favorite",R.drawable.sample),
                new ItemData("Like",R.drawable.sample),
                new ItemData("Rating",R.drawable.sample)};

        // 2. set layoutManger
        recyclerView.setLayoutManager(new LinearLayoutManager(this));
        // 3. create an adapter
        MyAdapter mAdapter = new MyAdapter(itemsData);
        // 4. set adapter
        recyclerView.setAdapter(mAdapter);
        // 5. set item animator to DefaultAnimator
        //recyclerView.setItemAnimator(new DefaultItemAnimator());
        recyclerView.setHasFixedSize(true);
    }

//build.gradle

apply plugin: 'com.android.application'

android {
    compileSdkVersion 20
    buildToolsVersion '19.1.0'

    defaultConfig {
        applicationId "com.domain.project"
        minSdkVersion 19
        targetSdkVersion 20
        versionCode 1
        versionName "1.0"
    }

    buildTypes {
        release {
            runProguard false
            proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
        }
    }
}

dependencies {
    compile fileTree(include: ['*.jar'], dir: 'libs')
    compile 'com.android.support:support-v4:+'
    compile 'com.android.support:support-v13:+'
    compile project(':facebook-3.15')
    compile project(':parse-1.5.1')
    compile project(':viewpagerindicator-2.4.1')
    compile 'com.github.manuelpeinado.fadingactionbar:fadingactionbar:3.1.2'
    compile 'com.android.support:cardview-v7:+'
    compile 'com.android.support:recyclerview-v7:+'
    compile 'com.google.android.gms:play-services:+'
}

configurations {
    // to avoid double inclusion of support libraries
    all*.exclude group: 'com.android.support', module: 'support-v4'
}

//LOGCAT

08-24 17:49:27.626  27544-27544/com.domain.project E/AndroidRuntime﹕ FATAL EXCEPTION: main
    Process: com.domain.project, PID: 27544
    java.lang.RuntimeException: Unable to start activity ComponentInfo{com.domain.project/com.domain.project.MainActivity}: android.view.InflateException: Binary XML file line #7: Error inflating class android.support.v7.widget.RecyclerView
            at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2215)
            at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2264)
            at android.app.ActivityThread.access$800(ActivityThread.java:144)
            at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1205)
            at android.os.Handler.dispatchMessage(Handler.java:102)
            at android.os.Looper.loop(Looper.java:136)
            at android.app.ActivityThread.main(ActivityThread.java:5139)
            at java.lang.reflect.Method.invokeNative(Native Method)
            at java.lang.reflect.Method.invoke(Method.java:515)
            at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:796)
            at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:612)
            at dalvik.system.NativeStart.main(Native Method)
     Caused by: android.view.InflateException: Binary XML file line #7: Error inflating class android.support.v7.widget.RecyclerView
            at android.view.LayoutInflater.createView(LayoutInflater.java:620)
            at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:696)
            at android.view.LayoutInflater.rInflate(LayoutInflater.java:755)
            at android.view.LayoutInflater.inflate(LayoutInflater.java:492)
            at android.view.LayoutInflater.inflate(LayoutInflater.java:397)
            at android.view.LayoutInflater.inflate(LayoutInflater.java:353)
            at com.android.internal.policy.impl.PhoneWindow.setContentView(PhoneWindow.java:343)
            at android.app.Activity.setContentView(Activity.java:1929)
            at com.domain.project.MainActivity.onCreate(MainActivity.java:35)
            at android.app.Activity.performCreate(Activity.java:5231)
            at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1087)
            at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2169)
            at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2264)
            at android.app.ActivityThread.access$800(ActivityThread.java:144)
            at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1205)
            at android.os.Handler.dispatchMessage(Handler.java:102)
            at android.os.Looper.loop(Looper.java:136)
            at android.app.ActivityThread.main(ActivityThread.java:5139)
            at java.lang.reflect.Method.invokeNative(Native Method)
            at java.lang.reflect.Method.invoke(Method.java:515)
            at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:796)
            at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:612)
            at dalvik.system.NativeStart.main(Native Method)
     Caused by: java.lang.reflect.InvocationTargetException
            at java.lang.reflect.Constructor.constructNative(Native Method)
            at java.lang.reflect.Constructor.newInstance(Constructor.java:423)
            at android.view.LayoutInflater.createView(LayoutInflater.java:594)
            at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:696)
            at android.view.LayoutInflater.rInflate(LayoutInflater.java:755)
            at android.view.LayoutInflater.inflate(LayoutInflater.java:492)
            at android.view.LayoutInflater.inflate(LayoutInflater.java:397)
            at android.view.LayoutInflater.inflate(LayoutInflater.java:353)
            at com.android.internal.policy.impl.PhoneWindow.setContentView(PhoneWindow.java:343)
            at android.app.Activity.setContentView(Activity.java:1929)
            at com.domain.project.MainActivity.onCreate(MainActivity.java:35)
            at android.app.Activity.performCreate(Activity.java:5231)
            at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1087)
            at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2169)
            at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2264)
            at android.app.ActivityThread.access$800(ActivityThread.java:144)
            at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1205)
            at android.os.Handler.dispatchMessage(Handler.java:102)
            at android.os.Looper.loop(Looper.java:136)
            at android.app.ActivityThread.main(ActivityThread.java:5139)
            at java.lang.reflect.Method.invokeNative(Native Method)
            at java.lang.reflect.Method.invoke(Method.java:515)
            at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:796)
            at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:612)
            at dalvik.system.NativeStart.main(Native Method)
     Caused by: java.lang.NoClassDefFoundError: android.support.v4.util.Pools$SimplePool
            at android.support.v7.widget.RecyclerView.<init>(RecyclerView.java:121)
            at android.support.v7.widget.RecyclerView.<init>(RecyclerView.java:213)
            at java.lang.reflect.Constructor.constructNative(Native Method)
            at java.lang.reflect.Constructor.newInstance(Constructor.java:423)
            at android.view.LayoutInflater.createView(LayoutInflater.java:594)
            at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:696)
            at android.view.LayoutInflater.rInflate(LayoutInflater.java:755)
            at android.view.LayoutInflater.inflate(LayoutInflater.java:492)
            at android.view.LayoutInflater.inflate(LayoutInflater.java:397)
            at android.view.LayoutInflater.inflate(LayoutInflater.java:353)
            at com.android.internal.policy.impl.PhoneWindow.setContentView(PhoneWindow.java:343)
            at android.app.Activity.setContentView(Activity.java:1929)
            at com.domain.project.MainActivity.onCreate(MainActivity.java:35)
            at android.app.Activity.performCreate(Activity.java:5231)
            at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1087)
            at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2169)
            at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2264)
            at android.app.ActivityThread.access$800(ActivityThread.java:144)
            at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1205)
            at android.os.Handler.dispatchMessage(Handler.java:102)
            at android.os.Looper.loop(Looper.java:136)
            at android.app.ActivityThread.main(ActivityThread.java:5139)
            at java.lang.reflect.Method.invokeNative(Native Method)
            at java.lang.reflect.Method.invoke(Method.java:515)
            at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:796)
            at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:612)
            at dalvik.system.NativeStart.main(Native Method)
nomongo
  • 3,435
  • 7
  • 30
  • 33
  • Here is a RecylerView Demo [recyclerviewdemo GitHub](https://github.com/writtmeyer/recyclerviewdemo) can you run this properly? – PrivatMamtora Aug 25 '14 at 01:34
  • I tried creating a new test project just for testing recyclerview and it works but unable to figure out why it does not work when including in an existing project. That's why I copied all the code from layout to the build.gradle – nomongo Aug 25 '14 at 04:13
  • recyclerview is only available when targeting Android-L at the moment, unless you are using a workaround to make it work on older versions? – athor Aug 25 '14 at 08:13

18 Answers18

61

Or... in my case, I was including the androidx version of RecyclerView in my dependencies (build.gradle) but using the other in my XML... Doh.

Replaced

android.support.v7.widget.RecyclerView

with

androidx.recyclerview.widget.RecyclerView

and it worked! :)

codingjeremy
  • 5,215
  • 1
  • 36
  • 39
14

In the xml declaration of the RecyclerView: Replace

<android.support.v7.widget.RecyclerView

with

<androidx.recyclerview.widget.RecyclerView

Hope this works ^_^

Eman Sallam
  • 301
  • 3
  • 3
  • this work for me too. i follow some tutorial which still use `android.support.v7.widget.RecyclerView` but my kotlin already use `androidx`. thankyouu – mbdrian Mar 22 '20 at 07:21
8

Please check your support libs are updated to latest..

com.android.support:support-v4: and com.android.support:recyclerview-v7

sreekumar
  • 2,439
  • 1
  • 21
  • 27
  • What exception you are getting ?? can you share the build.gradle ?? – sreekumar Oct 15 '15 at 11:11
  • android.view.InflateException: Binary XML file line #19: Error inflating class android.support.v7.widget.RecyclerView – Anirudh Oct 15 '15 at 14:20
  • java.lang.ClassNotFoundException: Didn't find class "android.support.v7.recyclerview.R$styleable" on path: DexPathList[[zip file "/data/app/com.example.merchant-2/base.apk"],nativeLibraryDirectories=[/vendor/lib, /system/lib]] – Anirudh Oct 15 '15 at 14:20
6

for the new API Version, on the build.gradle - project dependencies add :

implementation 'androidx.recyclerview:recyclerview:1.0.0'

and in the layout, you should replace :

android.support.v7.widget.RecyclerView

with

androidx.recyclerview.widget.RecyclerView
masbayu
  • 71
  • 1
  • 4
4

In your layout file:

Use:

androidx.recyclerview.widget.RecyclerView

Instead:

android.support.v7.widget.RecyclerView

It will work for you.

If you do not want to use Androidx then in your gradle.properties file and do this:

android.useAndroidX=false

android.enableJetifier=false
Muazzam A.
  • 647
  • 5
  • 17
2

My problem was that the library was compiled using JDK1.6 instead of 1.7.

Found the solution here link

guy_m
  • 3,110
  • 2
  • 19
  • 33
2

Add Dependencies in gradle file.

dependencies{
    compile 'com.android.support:appcompat-v7:23.3.0'
    compile 'com.android.support:recyclerview-v7:23.3.0'
}
Tunaki
  • 132,869
  • 46
  • 340
  • 423
Raj Karekar
  • 657
  • 6
  • 7
2

Just add following into your proguard-rules.pro,

-keep public class android.support.v7.widget.** { *; }
Melbourne Lopes
  • 4,817
  • 2
  • 34
  • 36
2

Make sure you have added proper dependencies for recyclerView. Then check whether you have dependecy for cardView.

If yes, then

  • remove card view dependency

  • sync project

  • then again add card view dependency

  • clean project

  • rebuild project

It worked for me

VeeyaaR
  • 291
  • 4
  • 7
  • 1
    This helped me to locate the problem. When I removed card view dependency and went to add it back again, in card view xml there was some attribute with unsupported value, which was not reported in compilation time, so after changing its value, everything worked. – Markonioninioni Sep 14 '22 at 17:09
1

I figured it out. Removing the following configuration in build.gradle makes the recyclerview work. This leads me to another question: android studio: gradle dependency error

--

configurations {
    // to avoid double inclusion of support libraries
    all*.exclude group: 'com.android.support', module: 'support-v4'
}
Community
  • 1
  • 1
nomongo
  • 3,435
  • 7
  • 30
  • 33
0

After trying everything on internet i solved recyclerview inflating error by observing small mistake. First, Did you check your android-support-v7-recyclerview.jar library present in libs folder? if it is then check if your manifest file that has target sdk version to 21

<uses-sdk
        android:minSdkVersion="11" //or whatever you need
        android:targetSdkVersion="21" />

may be this can help for someone in future and not wasting days behind it as i did.

WonderSoftwares
  • 2,800
  • 1
  • 15
  • 21
  • 2
    getting this error Error:(50, 19) error: cannot access ScrollingView class file for android.support.v4.view.ScrollingView not found. If I add V4, it fails to launch app on device. – Rohit Mandiwal Aug 02 '15 at 08:37
0

Check out my answer here Error inflating class RecyclerView. In short, you need to import recyclerview and appcompat dependencies and sync before you are trying to add RecyclerView to your XML.

Community
  • 1
  • 1
Ivan V
  • 3,024
  • 4
  • 26
  • 36
0

--- Quoted from Android website.

Dependencies

To use these features in versions of Android earlier than 5.0 (API level 21), include the Android v7 Support Library in your project as a Gradle dependency:

dependencies {
    compile 'com.android.support:appcompat-v7:21.0.+'
    compile 'com.android.support:cardview-v7:21.0.+'
    compile 'com.android.support:recyclerview-v7:21.0.+'
}
Zephyr
  • 6,123
  • 34
  • 33
0

For make it work under Eclipse in my case I added RecyclerView as Library in the workspace. And then added to my project under ANDROID LIBRARY. Finally. Three hours lost.

Alessandro Mattiuzzi
  • 2,309
  • 2
  • 18
  • 24
0

I had a similar same error message, and tried many of the suggested steps from the answers on this site.

java.lang.RuntimeException: Unable to start activity ComponentInfo{com.abc.def/com.abc.def.MainActivity}: android.view.InflateException: Binary XML file line #8:

Finally realized that for some reasons the tag in my layout was:

android.support.v7.internal.widget.RecyclerView 

instead of

android.support.v7.widget.RecyclerView. 

I am not sure how 'internal' crept in between v7 and widget, but once I removed that, the error went away. Not saying other people will make the same mistake, but just to let people know that a typo somewhere in your layout xml could be the cause of this error message.

a-hegde
  • 31
  • 2
0

Check your layout.xml file...Cant stop my laughing... I made a stupid mistake...

I put

<android.support.v7.wodget.RecyclerView

instead of

<android.support.v7.widget.RecyclerView

look at the small 'o', it wasted me 30 mins or more to check other files... [looking forward my answer can save your time]

0

Add below line in Gradle file:

dependencies {
    //recyclerview
    implementation 'androidx.recyclerview:recyclerview:1.0.0'
}

Add below code in your activity layout.xml:

<?xml version="1.0" encoding="utf-8"?>
<androidx.constraintlayout.widget.ConstraintLayout 
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:layout_width="match_parent"
android:layout_height="match_parent">

<androidx.recyclerview.widget.RecyclerView
    android:id="@+id/recyclerview"
    android:layout_width="0dp"
    android:layout_height="0dp"
    app:layout_constraintBottom_toBottomOf="parent"
    app:layout_constraintEnd_toEndOf="parent"
    app:layout_constraintStart_toStartOf="parent"
    app:layout_constraintTop_toTopOf="parent" />

</androidx.constraintlayout.widget.ConstraintLayout>

Your Android studio auto imports the androidx recyclerview.

AndroidX is a major improvement to the original Android Support Library. Like the Support Library, AndroidX ships separately from the Android OS and provides backwards-compatibility across Android releases.

Here is the reference AndroidX: https://developer.android.com/jetpack/androidx

-1

I too got same exception.

simple solution is add layout_behaviour to recycler view:

app:layout_behavior="@string/appbar_scrolling_view_behavior"
Fruchtzwerg
  • 10,999
  • 12
  • 40
  • 49
thiru-wta
  • 317
  • 3
  • 5