6

After updating to Android Studio 3.2, I've been getting a "Probable bugs" from lint saying:

"Not annotated method overrides method annotated with @NonNull".

I had no issue before updating to Android Studio 3.2, how do I solve this?

@NonNull
@Override
public View getView(int position, @Nullable View convertView, @NonNull ViewGroup parent) {
    View row = convertView;
    ViewHolder holder;

    if (convertView == null) {
        holder = new ViewHolder();
        row = LayoutInflater.from(context).inflate(R.layout.gallery_view_row, parent, false);
        holder.imageView = row.findViewById(R.id.filePath);
        row.setTag(holder);
    } else holder = (ViewHolder) row.getTag();

    String file_path = objects.get(position);
    GlideApp.with(context).load(MovieDB.IMAGE_URL + context.getResources().getString(R.string.galleryImgSize) + file_path)
            .into(holder.imageView);
    return row;
}

Android Lint never flagged this method before Android Studio 3.2 update, but now I get 2 flags on the method and on the "parent" parameter

Here are the 2 imports used

import androidx.annotation.NonNull;
import androidx.annotation.Nullable;

The problem only exists the the "ArrayAdapter" class, the superclass has those 5 imports highlighted in red

import android.annotation.ArrayRes;
import android.annotation.IdRes;
import android.annotation.LayoutRes;
import android.annotation.NonNull;
import android.annotation.Nullable;
Karl Ghosn
  • 117
  • 3
  • 13

6 Answers6

11

I was having this same problem, finally discovered a fix, hope it works for you...

Open Settings, select "Editor", then "Inspections".

In the list of inspections, go to "Probable Bugs" and then "@NotNull/@Nullable problems".

On the right pane, select the "CONFIGURE ANNOTATIONS" button.

Add "androidx.annotation.Nullable" and "androidx.annotation.NonNull" to the respective lists. I also made them the default.

No longer seeing this maddening behavior.

Screenshot

tliebeck
  • 816
  • 1
  • 8
  • 19
0

Any method parameter where this warning appears, annotate it with @NonNull. Any method that you're overriding where this appears, do the same (on the line either over or under @Override).

sbearben
  • 323
  • 6
  • 16
  • I already have annotated @NonNull to the methods and parameters, it's just that Android Lint is flagging these methods after 3.2 update. What's the problem in the update? – Karl Ghosn Sep 30 '18 at 19:50
0

Add the @NonNull annotation to your method:

@NonNull
@Override
public void myOverridenMethod() {
    //your code
}

Or just ignore it.

TheWanderer
  • 16,775
  • 6
  • 49
  • 63
0

"Not annotated method overrides method annotated with @NonNull".

It's pretty clear.

You probably should remove one of those @NonNull from the method (OR maybe those who are already added in the method and just making the method @NonNull), So:

@NonNull
@Override
public View getView(int position, View convertView, ViewGroup parent)

This will tell that the getView can't be null with any of those parameters inside.

ʍѳђઽ૯ท
  • 16,646
  • 7
  • 53
  • 108
  • It doesn't work. Could it be related to the migration to AndroidX? – Karl Ghosn Sep 30 '18 at 19:57
  • That's just a lint warning. So, if no errors-crashes comes out, there would be no problem with my provided codes. However, I'd prefer using `Kotlin` with the new AndroidX. You can Also try adding `@NonNull` to the parameters and remove the `@NonNull` of the method and then checking to see what happens. – ʍѳђઽ૯ท Sep 30 '18 at 19:59
0

Try to invalidate caches and restart Android Studio.

Ernest Zamelczyk
  • 2,562
  • 2
  • 18
  • 32
0

I have same problem because my android gradle tools too old(2.x) just upgrade project android gradle tools to 3.x solve this.

dependencies {
    classpath 'com.android.tools.build:gradle:3.2.1'
}
AlphaBoom
  • 56
  • 6