Chinez
Chinez

Reputation: 593

The following classes could not be instantiated: - androidx.recyclerview.widget.RecyclerView

I'm currently working on an app in android studio that requires using the recyclerview. After writing the code, the app seems to show no error so far except my XML design tab that issues out the following output on the issues section - "The following classes could not be instantiated: androidx.recyclerview.widget.RecyclerView

I've tried looking for a solution to it on this site but couldn't find any similar issue.

This is the code I used for recyclerview: <androidx.recyclerview.widget.RecyclerView

I as well implemented it on build.gradle:

dependencies {
    implementation '"androidx.recyclerview:recyclerview:1.1.0"'

I also added android.view.LayoutInflater to the main java file

Anything else I didn't do correctly?

My layout.xml file, the issue message for it, and the build.gradle are below:

  1. https://i.sstatic.net/ZRxK9.png
  2. https://i.sstatic.net/B9qR4.png
  3. https://i.sstatic.net/NR4vR.png

Upvotes: 0

Views: 208

Answers (1)

Tobi
Tobi

Reputation: 898

Try to change your xml to this:

<?xml version="1.0" encoding="utf-8"?>
<androidx.constraintlayout.widget.ConstraintLayout 
    xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:app="http://schemas.android.com/apk/res-auto"
    android:layout_width="match_parent"
    android:layout_height="match_parent">

    <androidx.recyclerview.widget.RecyclerView
        android:id="@+id/recycler"
        android:layout_width="0dp"
        android:layout_height="0dp"
        app:layout_constraintBottom_toBottomOf="parent"
        app:layout_constraintEnd_toEndOf="parent"
        app:layout_constraintStart_toStartOf="parent"
        app:layout_constraintTop_toTopOf="parent" />
</androidx.constraintlayout.widget.ConstraintLayout>

I'm not sure whether it is possible to have a recyclerview as root of a fragment.

Upvotes: 1

Related Questions