Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

onCreateDialog not annotated method overrides method annotated with @NonNull

Tags:

android

I am creating DialogFragment and when I want to override onCreateDialog I receive the following warning:

not annotated method overrides method annotated with @NonNull

@Override
public Dialog onCreateDialog(Bundle savedInstanceState) {
    return super.onCreateDialog(savedInstanceState);
}

If I want to place that annotation to my method, Android Studio can't find that annotation.

Why is this happening? Thanks for your help.

like image 530
user3339562 Avatar asked Mar 23 '15 15:03

user3339562


2 Answers

Because you override a method which is defined with a @NonNull annotation (meaning the method must not return null), and you are not using the same annotation in your overridden implementation, so that makes it a mismatch.

Please search for your question before submitting, this is asked many times.

Meaning of Android Studio error: Not annotated parameter overrides @NonNull parameter

(Edit: Fixed meaning of @NonNull annotation, thanks ci_)

like image 122
JHH Avatar answered Oct 07 '22 22:10

JHH


Looking at definition of the onCreateDialog method in DialogFragment, you will see:

@NonNull
public Dialog onCreateDialog(Bundle savedInstanceState)

So your code should include the same @NonNull annotation like this:

@Override
@NonNull
public Dialog onCreateDialog(Bundle savedInstanceState) {
    return super.onCreateDialog(savedInstanceState);
}
like image 45
Sean Lao Avatar answered Oct 07 '22 23:10

Sean Lao