Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Error Inflating Class android.v7.widget.RecyclerView

I am trying to learn about RecyclerView from scratch, and hence I tried to create a view using it. But as soon as I try to open the activity there seems to be an error: Error inflating class android.v7.widget.RecyclerView or class android.v7.widget.RecyclerView not found.

I tried changing dependencies, update sdktargets, checked the correct import and tried all previously available help. But I still cannot correct or remove error. So please before closing as duplicate and deleting the question, help me solve this error.

Here is my build.gradle:

 {
    compileSdkVersion 26
    defaultConfig {
        applicationId "com.example.nysil.newsnow"
        minSdkVersion 21
        targetSdkVersion 26
        versionCode 1
        versionName "1.0"
        testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner"
    }
    buildTypes {
        release {
            minifyEnabled false
            proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
        }
    }
}

dependencies {
    implementation fileTree(dir: 'libs', include: ['*.jar'])
    implementation 'com.android.support:appcompat-v7:26+'
    implementation 'com.android.support.constraint:constraint-layout:1.0.2'
    testImplementation 'junit:junit:4.12'
    androidTestImplementation 'com.android.support.test:runner:1.0.1'
    androidTestImplementation 'com.android.support.test.espresso:espresso-core:3.0.1'

    compile 'com.android.support:recyclerview-v7:26+'
}

Here is my layout file of Recycler View:

<android.v7.widget.RecyclerView
    xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_height="match_parent"
    android:layout_width="match_parent"
    android:id="@+id/recyclerView"

    />

This is the error debugger is showing:

    E/MultiWindowProxy: getServiceInstance failed!
D/AndroidRuntime: Shutting down VM
E/AndroidRuntime: FATAL EXCEPTION: main
                  Process: com.example.nysil.newsnow, PID: 26793
                  java.lang.RuntimeException: Unable to start activity ComponentInfo{com.example.nysil.newsnow/com.example.nysil.newsnow.ShowNews}: android.view.InflateException: Binary XML file line #0: Binary XML file line #0: Error inflating class android.v7.widget.RecyclerView
                      at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2585)
                      at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2667)
                      at android.app.ActivityThread.-wrap11(ActivityThread.java)
                      at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1494)
                      at android.os.Handler.dispatchMessage(Handler.java:111)
                      at android.os.Looper.loop(Looper.java:207)
                      at android.app.ActivityThread.main(ActivityThread.java:5776)
                      at java.lang.reflect.Method.invoke(Native Method)
                      at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:789)
                      at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:679)
                   Caused by: android.view.InflateException: Binary XML file line #0: Binary XML file line #0: Error inflating class android.v7.widget.RecyclerView
                      at android.view.LayoutInflater.inflate(LayoutInflater.java:539)
                      at android.view.LayoutInflater.inflate(LayoutInflater.java:423)
                      at android.view.LayoutInflater.inflate(LayoutInflater.java:374)
                      at android.support.v7.app.AppCompatDelegateImplV9.setContentView(AppCompatDelegateImplV9.java:287)
                      at android.support.v7.app.AppCompatActivity.setContentView(AppCompatActivity.java:139)
                      at com.example.nysil.newsnow.ShowNews.onCreate(ShowNews.java:14)
                      at android.app.Activity.performCreate(Activity.java:6582)
                      at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1113)
                      at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2532)
                      at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2667) 
                      at android.app.ActivityThread.-wrap11(ActivityThread.java) 
                      at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1494) 
                      at android.os.Handler.dispatchMessage(Handler.java:111) 
                      at android.os.Looper.loop(Looper.java:207) 
                      at android.app.ActivityThread.main(ActivityThread.java:5776) 
                      at java.lang.reflect.Method.invoke(Native Method) 
                      at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:789) 
                      at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:679) 
                   Caused by: android.view.InflateException: Binary XML file line #0: Error inflating class android.v7.widget.RecyclerView
                      at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:776)
                      at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:704)
                      at android.view.LayoutInflater.inflate(LayoutInflater.java:492)
                      at android.view.LayoutInflater.inflate(LayoutInflater.java:423) 
                      at android.view.LayoutInflater.inflate(LayoutInflater.java:374) 
                      at android.support.v7.app.AppCompatDelegateImplV9.setContentView(AppCompatDelegateImplV9.java:287) 
                      at android.support.v7.app.AppCompatActivity.setContentView(AppCompatActivity.java:139) 
                      at com.example.nysil.newsnow.ShowNews.onCreate(ShowNews.java:14) 
                      at android.app.Activity.performCreate(Activity.java:6582) 
                      at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1113) 
                      at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2532) 
                      at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2667) 
                      at android.app.ActivityThread.-wrap11(ActivityThread.java) 
                      at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1494) 
                      at android.os.Handler.dispatchMessage(Handler.java:111) 
                      at android.os.Looper.loop(Looper.java:207) 
                      at android.app.ActivityThread.main(ActivityThread.java:5776) 
                      at java.lang.reflect.Method.invoke(Native Method) 
                      at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:789) 
                      at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:679) 
                   Caused by: java.lang.ClassNotFoundException: Didn't find class "android.v7.widget.RecyclerView" on path: DexPathList[[zip file "/data/app/com.example.nysil.newsnow-2/base.apk"],nativeLibraryDirectories=[/data/app/com.example.nysil.newsnow-2/lib/arm64, /vendor/lib64, /system/lib64]]
                      at dalvik.system.BaseDexClassLoader.findClass(BaseDexClassLoader.java:56)
                      at java.lang.ClassLoader.loadClass(ClassLoader.java:511)
                      at java.lang.ClassLoader.loadClass(ClassLoader.java:469)
                      at android.view.LayoutInflater.createView(LayoutInflater.java:583)
                      at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:764)
                      at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:704) 
                      at android.view.LayoutInflater.inflate(LayoutInflater.java:492) 
                      at android.view.LayoutInflater.inflate(LayoutInflater.java:423) 
                      at android.view.LayoutInflater.inflate(LayoutInflater.java:374) 
                      at android.support.v7.app.AppCompatDelegateImplV9.setContentView(AppCompatDelegateImplV9.java:287) 
                      at android.support.v7.app.AppCompatActivity.setContentView(AppCompatActivity.java:139) 
                      at com.example.nysil.newsnow.ShowNews.onCreate(ShowNews.java:14) 
                      at android.app.Activity.performCreate(Activity.java:6582) 
                      at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1113) 
                      at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2532) 
                      at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2667) 
                      at android.app.ActivityThread.-wrap11(ActivityThread.java) 
                      at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1494) 
                      at android.os.Handler.dispatchMessage(Handler.java:111) 
                      at android.os.Looper.loop(Looper.java:207) 
                      at android.app.ActivityThread.main(ActivityThread.java:5776) 
                      at java.lang.reflect.Method.invoke(Native Method) 
                      at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:789) 
                      at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:679) 
                    Suppressed: java.lang.ClassNotFoundException: android.v7.widget.RecyclerView
                      at java.lang.Class.classForName(Native Method)
                      at java.lang.BootClassLoader.findClass(ClassLoader.java:781)
                      at java.lang.BootClassLoader.loadClass(ClassLoader.java:841)
                      at java.lang.ClassLoader.loadClass(ClassLoader.java:504)
                            ... 22 more
                   Caused by: java.lang.NoClassDefFoundError: Class not found using the boot class loader; no stack trace available
like image 729
Neeraj Yadav Avatar asked Jan 26 '18 08:01

Neeraj Yadav


1 Answers

I believe you are using the wrong RecyclerView. Use

android.support.v7.widget.RecyclerView

instead of

android.v7.widget.RecyclerView
like image 128
Umair Avatar answered Oct 10 '22 04:10

Umair