错误
Error:(16, 10) 错误: com.xxx.xxx.presenter.MySorePresenter cannot be provided without an @Inject constructor or from an @Provides- or @Produces-annotated method.
com.xxx.xxx.MySorePresenter is injected at
com.xxx.xxx.view.activity.MySoreActivity.presenter
com.xxx.xxx.view.activity.MySoreActivity is injected at
com.xxx.xxx.di.components.MySoreComponent.inject(activity)
定位错误
-看报错指向,其指向的是:MySoreComponent
@UserScope
@Component(dependencies = ApplicationComponent.class,modules = {MySoreModule.class, ActivityModule.class})
public interface MySoreComponent extends ActivityComponent{
void inject(MySoreActivity activity);
}
- 其实际指向的是MySoreModule
@Module
public class MySoreModule {
private MySoreContract.View mView;
public MySoreModule(MySoreContract.View mView){
this.mView = mView;
}
@Provides
@UserScope
public MySoreContract.View provideView(){
return mView;
}
}
- 再看一下MySoreContract 类和MySorePresenter 里面的内容
public interface MySoreContract {
interface Presenter{
void getListByPage(int page,String userid,String pageId,String method);
}
interface View{
void showLoading();
void showNoData();
void updateListUI(List<TaskInfo.Ds> dsList);
void showOnFailure();
}
}
- MySorePresenter
public class MySorePresenter implements MySoreContract.Presenter {
private MySoreContract.View view;
public MySorePresenter(MySoreContract.View view){
this.view = view;
}
@Override
public void getListByPage(int page, String userid, String pageId, String method) {
}
}
解决错误
在MySorePresenter 类中能过@Inject注解其构造函数,如下:
public class MySorePresenter implements MySoreContract.Presenter {
private MySoreContract.View view;
@Inject
public MySorePresenter(MySoreContract.View view){
this.view = view;
}
@Override
public void getListByPage(int page, String userid, String pageId, String method) {
}
}