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;
The first step is to build a new module that will house your annotations. Go to Android Studio and then click on File -> New ->New Module then choose Kotlin and after that, you need to add a name to the module like you usually do with your android projects. Name the module gfg-annotations. Set the package to com.
public annotation Nullable. Denotes that a parameter, field or method return value can be null. When decorating a method call parameter, this denotes that the parameter can legitimately be null and the method will gracefully deal with it. Typically used on optional parameters.
@NonNull – The compiler can determine cases where a code path might receive a null value, without ever having to debug a NullPointerException. @ReadOnly – The compiler will flag any attempt to change the object. This is similar to Collections. unmodifiableList, but more general and verified at compile time.
To enable annotations in your project, add the support-annotations dependency to your library or app. Any annotations you add then get checked when you run a code inspection or lint task.
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.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With