Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/android/226.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Android Dagger@Injects为空_Android_Dependency Injection_Dagger - Fatal编程技术网

Android Dagger@Injects为空

Android Dagger@Injects为空,android,dependency-injection,dagger,Android,Dependency Injection,Dagger,匕首在踢我的屁股 我有下面的布局 注入到对象图中的主活动 MainActivity@注入一个MainPresenter接口。这是通过返回具体实现的main模块提供的 具体的MainPresenter实现采用FileContentInteractor接口。这在InteractorModule中提供,它返回一个具体的FileContentInteractor实现 MainModule可以这样做,因为它包含InteractorModule.class 到目前为止,一切都很好。从这一点开始,事情就变

匕首在踢我的屁股

我有下面的布局

  • 注入到对象图中的主活动
  • MainActivity@注入一个MainPresenter接口。这是通过返回具体实现的main模块提供的
  • 具体的MainPresenter实现采用FileContentInteractor接口。这在InteractorModule中提供,它返回一个具体的FileContentInteractor实现
  • MainModule可以这样做,因为它包含InteractorModule.class
到目前为止,一切都很好。从这一点开始,事情就变得棘手了

具体的FileContentInteractor实现使用@Inject注入一些成员变量。这些成员变量都是通过各自模块提供具体实现的接口

例如@Inject ThreadExecutor ThreadExecutor。我想这是因为

  • InteractorModule包括ExecutorModule.class
  • ExecutorModule.class@以TaasExecutor对象的形式提供了ThreadExecutor的具体实现
  • TaskExecutor对象没有注入的依赖项
当我运行应用程序并打开MainActivity时,会发生以下情况:

  • MainActivity调用MainPresenter实现的方法-工作正常
  • MainPresenter有一个FileContentInteractor实现,并在其上调用一个方法-works
  • FileContentInteractor实现中的方法尝试调用ThreadExecutor实现中的方法(该方法被@Injected作为成员变量)。此操作失败,因为@Injected ThreadExecutor实现为null

有人能帮忙吗?

好吧,看来我是在自讨苦吃

我用@Inject成员引用了具体的类,但使用了@Inject提供的接口

将@Inject成员从类修改为接口修复了它