Home » Android » android – RecyclerView ClassNotFound

android – RecyclerView ClassNotFound

Posted by: admin April 23, 2020 Leave a comment

Questions:

I tried to add RecyclerView and CardView into my project

dependencies {
compile 'com.android.support:appcompat-v7:21.0.0'
compile 'com.android.support:support-v13:21.0.0'
compile 'com.android.support:cardview-v7:21.0.0'
compile 'com.android.support:recyclerview-v7:21.0.0'
compile 'com.viewpagerindicator:library:[email protected]'
compile project(':facebook')
}

it compiles, but I got below exception when run it on device

Caused by: java.lang.ClassNotFoundException: Didn't find class "android.view.RecyclerView" on path: DexPathList[[zip file "/data/app/xxxx.apk"],nativeLibraryDirectories=[/data/app-lib/xxxx, /vendor/lib, /system/lib]]
        at dalvik.system.BaseDexClassLoader.findClass(BaseDexClassLoader.java:56)
        at java.lang.ClassLoader.loadClass(ClassLoader.java:497)
        at java.lang.ClassLoader.loadClass(ClassLoader.java:457)
        at android.view.LayoutInflater.createView(LayoutInflater.java:559)
        at android.view.LayoutInflater.onCreateView(LayoutInflater.java:652)
How to&Answers:

Problem in your layout. Change

<RecyclerView 
   ...

To

<android.support.v7.widget.RecyclerView
   ...

If you create RecyclerView programmatically – make sure you have proper import:

import android.support.v7.widget.RecyclerView;

Answer:

I did all what have been said in this post but nothing worked.

What did work for me:

1.Add this as say up in your build.gradle:

compile 'com.android.support:support-v4:21.0.3'
compile 'com.android.support:appcompat-v7:21.0.0'
compile 'com.android.support:recyclerview-v7:+'
compile 'com.android.support:cardview-v7:+'

2.Add the RecyclerView as a standar View and indicate the class:

    <view
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    class="android.support.v7.widget.RecyclerView"
    android:id="@+id/my_recycler_view"
    />

3.Then add the imports:

import android.support.v7.widget.RecyclerView;

Hope this helps!

Answer:

If you are updated your android studio to v-3.4.2

then Change from

android.support.v7.widget.RecyclerView

to

androidx.recyclerview.widget.RecyclerView

it’s work for me.

Answer:

If you’re looking for solution in 2019, you could try to change android.support.v7.widget.RecyclerView for androidx.recyclerview.widget.RecyclerView. It works for me. Hope it helps!

Answer:

This worked for me:

compile 'com.android.support:support-v4:21.0.3'
compile 'com.android.support:appcompat-v7:21.0.0'
compile 'com.android.support:recyclerview-v7:+'
compile 'com.android.support:cardview-v7:+'

Best regards!

Answer:

in eclipse, you need to clear other(older) versions of android-support-v4.jar from other libraries which you import directly or indirectly.

for my instance ; my project(TurkRenkleri) includes MobilePlayGround which includes appcompat library(which has a older version of support v4 jar). So i didnt get the error given below, instead i got RecyclerView ClassNotFound.

after doing this , i finally got the error below, and understood problem therefore the solution(delete old jars).

[2015-04-29 00:59:53 - TurkRenkleri] Found 2 versions of android-support-v4.jar in the dependency list,
 [2015-04-29 00:59:53 - TurkRenkleri] but not all the versions are identical (check is based on SHA-1 only at this time).
 [2015-04-29 00:59:53 - TurkRenkleri] All versions of the libraries must be the same at this time.
 [2015-04-29 00:59:53 - TurkRenkleri] Versions found are:
 [2015-04-29 00:59:53 - TurkRenkleri] Path: E:\calisma alani\oyunlar\android-support-v7-appcompat\libs\android-support-v4.jar
 [2015-04-29 00:59:53 - TurkRenkleri]   Length: 621451
 [2015-04-29 00:59:53 - TurkRenkleri]   SHA-1: 5896b0a4e377ac4242eb2bc785220c1c4fc052f4
 [2015-04-29 00:59:53 - TurkRenkleri] Path: E:\calisma alani\oyunlar\RecyclerView\libs\android-support-v4.jar
 [2015-04-29 00:59:53 - TurkRenkleri]   Length: 1157388
 [2015-04-29 00:59:53 - TurkRenkleri]   SHA-1: 605c447c20ca216b5556af9f215af5d4bba1b117
 [2015-04-29 00:59:53 - TurkRenkleri] Jar mismatch! Fix your dependencies

Answer:

Make sure is compile ‘com.android.support:recyclerview-v7:22.2.0’

Answer:

This worked for me. Add this to app gradle

compile 'com.android.support:design:23.1.1'

Then in your layout

<android.support.v7.widget.RecyclerView
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:id="@+id/recyclerView"
    android:layout_centerVertical="true"
    android:layout_alignParentLeft="true"
    android:layout_alignParentStart="true" />

and in your activity

import android.support.v7.widget.RecyclerView;

and inside your onCreate

RecyclerView recyclerView;

Answer:

It is a Building problem…

Yes in few cases , The code was working previously and suddenly it
stopped working (crash at app startup) when I synced and built an
older version of the code.

The fix was to just close and restart Eclipse and clean the project
and clean all the dependent library projects. Then it started working
properly again.

It’s some sort of build problem in Eclipse, when refreshing the
project files.

Update: In particular, if you’ve accidentally modified the
“.classpath” file (to revert to an older version), Eclipse/Android SDK
can get confused and not build the project properly. When you restart
Eclipse and clean the project, Eclipse will re-modify the “.classpath”
file, and build properly.