匕首 - 班级没有注射成员

时间:2014-01-05 10:57:19

标签: android dagger

我正在尝试将Dagger集成到我的应用程序中。我遇到了一个问题。我在运行时收到此错误:

java.lang.IllegalStateException: Errors creating object graph:
    com.app.NavigationController has no injectable members. Do you want to add an injectable constructor? required by class com.app.fragments.LoginFragment

我试着研究其他类似的答案,但到目前为止没有任何帮助......

与图形构造相关的所有内容都与Android Activity Graphs示例中的实现非常相似。

我有两个模块ActivityModuleApplicationModule

@Module(
        includes = ApplicationModule.class,
        injects = {
                MainActivity.class,
                LoginFragment.class
        }
)
public class ActivityModule {

    private BaseActivity activity;

    public ActivityModule(BaseActivity activity) {
        this.activity = activity;
    }

    @Provides
    @Singleton
    NavigationController provideNavigation() {
        return new NavigationController(activity);
    }
}

另一个

@Module(
    injects = {
            MainActivity.class,
            LoginFragment.class},
    complete = false
)
public class ApplicationModule {

    private Context context;

    public ApplicationModule(Context context) {
        this.context = context;
    }

    @Provides
    @Singleton
    ApiService provideApiService() {
        ....
        return restAdapter.create(ApiService.class);
    }
}

我做错了什么?

更新:
添加更多细节:

片段:

public class LoginFragment extends BaseFragment {

    //...

    @Inject
    NavigationController navigation;

    //...

导航控制器:

public class NavigationController {

//...

public NavigationController(BaseActivity activity) {
    this.activity = activity;
}

//...
}

1 个答案:

答案 0 :(得分:2)

问题在这个Dagger中被回答GitHub issue #372