我有我想注入片段的 RegisterPresenterImpl 。当我调用该演示者的方法 register() 时,我的应用程序崩溃。它说我的演示者为空。
我该如何解决这个问题?
public class RegisterAccountFragment extends Fragment implements RegisterAccountView {
@Inject
RegisterAccountPresenterImpl registerPresenter;
public RegisterAccountFragment() {
// Required empty public constructor
}
@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container,
Bundle savedInstanceState) {
// Inflate the layout for this fragment
View v = inflater.inflate(R.layout.fragment_register_account, container, false);
DaggerRegisterAccountComponent.builder()
.netComponent(((App) getActivity().getApplicationContext()).getNetComponent())
.registerAccountModule(new RegisterAccountModule(this))
.build()
.inject(this);
registerPresenter.register(getName(), getEmail(), getPassword(), getConfirm());
}
}
组件接口:
@FragmentScoped
@Component(dependencies = NetComponent.class, modules = RegisterAccountModule.class)
public interface RegisterAccountComponent {
void inject(RegisterAccountFragment fragment);
}
这是模块类:
@Module
public class RegisterAccountModule {
private RegisterAccountView view;
public RegisterAccountModule(RegisterAccountView view){
this.view = view;
}
@Provides
@FragmentScoped
RegisterAccountView providesRegisterAccountView(){
return view;
}
}
这是一个名为 RegisterPresenterImpl 的类
public class RegisterAccountPresenterImpl implements RegisterAccountPresenter{
private RegisterAccountView view;
private Retrofit retrofit;
private CompositeDisposable compositeDisposable = new CompositeDisposable();
@Inject
public RegisterAccountPresenterImpl(Retrofit retrofit, RegisterAccountView view){
this.retrofit = retrofit;
this.view = view;
}
@Override
public void register(String name, String email, String password, String confirm) {
// CODE
}
}