Reputation: 3729
Using Android Studio 4.2.1 and trying to handle a RecyclerView
I get an error when trying to build my own ViewAdapter
.
I've added implementation 'androidx.recyclerview:recyclerview:1.2.1'
to my build.gradle
:app file.
My activity_main file is like this:
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout 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"
android:layout_width="match_parent"
android:layout_height="match_parent"
tools:context=".MainActivity"
android:padding="10dp">
<androidx.recyclerview.widget.RecyclerView
android:layout_width="match_parent"
android:layout_height="match_parent"
android:id="@+id/contactsRV"/>
</RelativeLayout>
I've created another layout file like this:
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:padding="10dp"
android:id="@+id/parent">
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Contact Name"
android:id="@+id/txtName"/>
</RelativeLayout>
I've created a Java class like this
package com.domain.packagename;
import android.view.View;
import androidx.annotation.NonNull;
import androidx.recyclerview.widget.RecyclerView;
public class ContactRVAdapter {
public class ViewHolder extends RecyclerView.ViewHolder{
public ViewHolder(@NonNull @org.jetbrains.annotations.NotNull View itemView) {
super(itemView);
}
}
}
The NotNull
is Red and the "Problems" pane says "Cannot resolve symbol 'NotNull'".
The public ViewHolder()
... was auto-generated.
What, if anything, am I doing wrong? (This is not exactly homework. I'm not in an organized class. I am following on online tutorial that's about a year old and the instructor's AS is a slightly older version than mine.)
Upvotes: 1
Views: 875
Reputation: 40878
You can discard it by removing the @org.jetbrains.annotations.NotNull
annotation:
public ViewHolder(@NonNull View itemView) {
Or if you wish to leave it you need to include its dependency in build.gradle (Module level):
implementation 'org.jetbrains:annotations:16.0.2'
Upvotes: 1