更新到Android Studio 3.2之后,我从 Lint 上得到了一个“可能的错误”:

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

在更新到Android Studio 3.2之前,我没有任何问题,该如何解决?
@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从未在Android Studio 3.2更新之前标记此方法,但是现在我在该方法和“parent”参数上获得了2个标记

这是使用的2种进口商品
import androidx.annotation.NonNull;
import androidx.annotation.Nullable;

该问题仅存在于“ArrayAdapter”类中,父类(super class)的那5个导入用红色突出显示
import android.annotation.ArrayRes;
import android.annotation.IdRes;
import android.annotation.LayoutRes;
import android.annotation.NonNull;
import android.annotation.Nullable;

最佳答案

我遇到了同样的问题,终于找到了解决方法,希望它对您有用...

打开设置,选择“编辑器”,然后选择“检查”。

在检查列表中,转到“可能的错误”,然后转到“@ NotNull/@ Nullable问题”。

在右侧 Pane 中,选择“配置注释”按钮。

将“androidx.annotation.Nullable”和“androidx.annotation.NonNull”添加到各自的列表中。我也将它们设置为默认值。

不再看到这种疯狂的行为。

android - Android Studio 3.2之后如何解决NonNull注释?-LMLPHP

10-07 20:04
查看更多