0

I use this code but error comes, it says that "cannot find class symbol nullable"

package com.example.fd.miwok;

import android.view.View;
import android.view.ViewGroup;
import android.widget.ArrayAdapter;

public class WordAdapter extends ArrayAdapter<Word> {
    @androidx.annotation.NonNull
    @Override
    public View getView(int position, @androidx.annotation.Nullable View convertView, @androidx.annotation.NonNull ViewGroup parent) {
        return super.getView(position, convertView, parent);
    }
}
tomcek112
  • 1,516
  • 10
  • 16
Davidsen
  • 11
  • 4
  • 1
    Possible duplicate of [Can't find @Nullable inside javax.annotation.\*](https://stackoverflow.com/questions/19030954/cant-find-nullable-inside-javax-annotation) – Suyash Mittal Feb 08 '19 at 09:56

2 Answers2

0

You are using annotations from androidx.annotation package. You must include it in your project by adding this dependency in your build.gradle file.

implementation 'androidx.annotation:annotation:1.0.1'
ycesar
  • 420
  • 5
  • 9
0

You are not using AndroidX, so you should be using the Nullable and NonNull provided by the regular Android library in android.support.annotation

package com.example.fd.miwok;

import android.support.annotation.NonNull;
import android.support.annotation.Nullable;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ArrayAdapter;

public class WordAdapter extends ArrayAdapter<Word> {
    @NonNull
    @Override
    public View getView(int position, @Nullable View convertView, @NonNull ViewGroup parent) {
        return super.getView(position, convertView, parent);
    }
}
Leo Aso
  • 11,898
  • 3
  • 25
  • 46
  • this error message occur "Caused by: java.nio.file.DirectoryNotEmptyException: C:\Users\FD\AndroidStudioProjects\app\build\generated\not_namespaced_r_class_sources\debug\processDebugResources\r\androidx" – Davidsen Feb 08 '19 at 10:19
  • Clean your project and build again. – Leo Aso Feb 08 '19 at 10:20
  • thank you, i works for me. But anyway what's AndroidX actually? – Davidsen Feb 09 '19 at 11:40
  • I haven't studied much about it myself, but you can consider it a sort of upgrade of the existing Android libraries like the design libraries and support libraries and such. There is documentation on the Android developers site, so you can read up on it to know more. – Leo Aso Feb 09 '19 at 17:45