Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

RecyclerView ClassNotFound

Tags:

android

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)
like image 884
Rene Xu Avatar asked Oct 28 '14 09:10

Rene Xu


4 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;
like image 55
localhost Avatar answered Nov 18 '22 10:11

localhost


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!

like image 30
khsoldier Avatar answered Nov 18 '22 09:11

khsoldier


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!

like image 3
David Pereira Avatar answered Nov 18 '22 08:11

David Pereira


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;
like image 2
Mucahid Uslu Avatar answered Nov 18 '22 10:11

Mucahid Uslu