2

i have a problem when i try to access to recycle view i got the gray screen and it not working here is photo is my problem [this is the error] [1] [1]: https://i.stack.imgur.com/8tec9.png

and this is my code in xml

 <?xml version="1.0" encoding="utf-8"?>
<layout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:app="http://schemas.android.com/apk/res-auto"
    xmlns:tools="http://schemas.android.com/tools">

    <data>
<variable
    name="viewModel"
    type="com.example.moviesnerd.ui.MovieViewModel" />
    </data>

    <androidx.constraintlayout.widget.ConstraintLayout
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        tools:context=".ui.MainActivity">

    <androidx.recyclerview.widget.RecyclerView
            android:id="@+id/recyclerView"
        android:scrollbars="vertical"
        android:layout_width="match_parent"
            android:layout_height="0dp"
            app:layout_constraintBottom_toTopOf="@+id/button"
            app:layout_constraintLeft_toLeftOf="parent"
            app:layout_constraintRight_toRightOf="parent"
            app:layout_constraintTop_toTopOf="parent"
        />

        <Button
            android:id="@+id/button"
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:onClick="@{()->viewModel.getName()}"
            android:text="Show Movie"
            app:layout_constraintBottom_toBottomOf="parent"
            app:layout_constraintEnd_toEndOf="parent"
            app:layout_constraintHorizontal_bias="1.0"
            app:layout_constraintStart_toStartOf="parent" />

    </androidx.constraintlayout.widget.ConstraintLayout>
</layout>

and here is my dependencies

 dependencies {
    implementation fileTree(dir: "libs", include: ["*.jar"])
    implementation 'androidx.appcompat:appcompat:1.2.0'
    implementation 'androidx.constraintlayout:constraintlayout:2.0.1'
    testImplementation 'junit:junit:4.13'
    androidTestImplementation 'androidx.test.ext:junit:1.1.2'
    androidTestImplementation 'androidx.test.espresso:espresso-core:3.3.0'
    implementation 'com.jakewharton:butterknife:10.2.3'
    annotationProcessor 'com.jakewharton:butterknife-compiler:10.2.3'

    // ViewModel and LiveData
    implementation "android.arch.lifecycle:extensions:1.1.1"
    implementation 'androidx.recyclerview:recyclerview:1.0.0'

    implementation "androidx.cardview:cardview:1.0.0"


} 

3 Answers3

1

Just do Build > Clean Project. I had the same issues and here is the question that I asked in Stackoverflow:

RecyclerView doesn't show up in Android Studio Preview

null_override
  • 467
  • 3
  • 10
  • 30
0

You added RecyclerView library Two Times, Delete Above and it will work

beqa
  • 1
  • 2
0

I am not familiar with androidx.constraintlayout.widget.ConstraintLayout but your RecyclerView android:layout_height="0dp".
Change it to wrap_content and it might work.

G Ganesh
  • 103
  • 7