OnCreateDialog non-annotated method overrides the method annotated with @NonNull

I create a DialogFragment, and when I want to override onCreateDialog , I get the following warning:

non-annotated method overrides the method annotated with @NonNull

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

If I want to post this annotation to my method, Android Studio will not be able to find this annotation.

Why is this happening? Thank you for your help.

+6
source share
2 answers

Because you are overriding the method that is defined by the @NonNull annotation (which means the method should not return null), and you are not using the same annotation in your overridden implementation, which makes it inconsistent.

Please find your question before submitting, this has been asked many times.

Android Studio error value: overridden parameters of annotated @NonNull parameters

(Edit: Fixed @NonNull annotation value, thanks ci _)

+3
source

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

 @NonNull public Dialog onCreateDialog(Bundle savedInstanceState) 

So your code should contain the same @NonNull annotations like this:

 @Override @NonNull public Dialog onCreateDialog(Bundle savedInstanceState) { return super.onCreateDialog(savedInstanceState); } 
+15
source

Source: https://habr.com/ru/post/984143/


All Articles