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)
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;
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!
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!
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;
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With