I have a method that can return a nullable object, I add the appropriate annotation to the method and to all other methods that use this object, but still get an error

Error:(17, 7) error: services.objects.response.CallServicePart is not nullable, but is being provided by @ui.dagger.dynamicFormComponent.PerDynamicForm @Provides @android.support.annotation.Nullable services.objects.response.CallServicePart ui.dagger.dynamicFormComponent.DynamicModule .getCallServicePart(models.AppModel) at: services.objects.response.CallServicePart is injected at ui.fragments.DynamicFormFragment.mServicePart ui.fragments.DynamicFormFragment is injected at ui.dagger.dynamicFormComponent.DynamicFormComponent.inject(iFragment) 

Here is my module

 @Module public class DynamicModule { .../// @PerDynamicForm @Provides @Nullable CallServicePart getCallServicePart(AppModel iAppModel) { return iAppModel.getServicePart(); } @PerDynamicForm @Provides @Nullable ServicePartFormQuestionsManager getServicePartFormQuestionsManager(@CallNumber long iCallNumber, @Nullable CallServicePart iServicePart) { ServicePartFormQuestionsManager manager = null; if (iServicePart != null) { manager = CallsManager.getInstance().getOpenCallData(iCallNumber).getServicePartFormQuestionManagerForPartCode(iServicePart.getPartCode()); } return manager; } .../// } 

What am I doing wrong?

  • And this method is nullable : iAppModel.getServicePart() ? - YurySPb

1 answer 1

The @Nullable says that the return value of a parameter, field, or method can be.

  • If a {@code @Provides} method is marked {@code @Nullable}, Dagger will only

  • allow well as @ {code @Nullable} as well. A component that
  • attempts to pair a {@code @Nullable} provision with a non - {@ code @Nullable} injection site
  • will fail to compile.

If the method is marked as @Nullabl e, Dagger allows injection only on links marked @Nullable. The component that is trying to compile the @Nullable condition with the help of the non @ Nullable command will zafelitsya.

 Error:(17, 7) error: services.objects.response.CallServicePart is not nullable 

So he swears, check that the class has annotations, just in case, make a clean project and rebuild.

  • Well, yes, I did not understand everything, I read it again. Now add - Shwarz Andrei
  • Yes, but the question shows that CallServicePart marked as Nullable , or not - Aleksey Timoshchenko