Rene Xu
Rene Xu

Reputation: 1103

RecyclerView ClassNotFound

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:2.4.1@aar'
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)

Upvotes: 34

Views: 18367

Answers (9)

lgallard
lgallard

Reputation: 462

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:+'

Upvotes: 0

Mucahid Uslu
Mucahid Uslu

Reputation: 417

you can use androidx recyclerview widget, this works !

 <androidx.recyclerview.widget.RecyclerView
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:layout_marginLeft="10dp"
    android:layout_marginRight="10dp"
    android:scrollbars="vertical"
    android:id="@+id/listExp"
    />

and import to code,

import androidx.recyclerview.widget.RecyclerView;

and then ready to use ,

 private RecyclerView recyclerViewExp;

Upvotes: 2

David Pereira
David Pereira

Reputation: 31

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!

Upvotes: 3

F0r3v3r-A-N00b
F0r3v3r-A-N00b

Reputation: 3003

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;

Upvotes: 0

Libin Thomas
Libin Thomas

Reputation: 1172

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

Upvotes: 0

khsoldier
khsoldier

Reputation: 51

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!

Upvotes: 5

Alp
Alp

Reputation: 1893

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

Upvotes: 0

localhost
localhost

Reputation: 5598

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;

Upvotes: 65

Sainath Patwary karnate
Sainath Patwary karnate

Reputation: 3195

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.

Upvotes: -2

Related Questions