なく提供することができない、今私はdagger2を学び、私はエラーを持っている理由を私は理解して傾ける開始:ダガー2は、コンストラクタ私の英語のため申し訳ありません
Error:(9, 10) error: test.dagger.dagger.modules.MainActivityPresenterModule cannot be provided without an @Inject constructor or from an @Provides- or @Produces-annotated method. test.dagger.dagger.modules.MainActivityPresenterModule is injected at test.dagger.view.activitys.MainActivity.mainActivityPresenterModule test.dagger.view.activitys.MainActivity is injected at test.dagger.dagger.components.AppComponent.injectMainActivity(mainActivity)
のApp
public class App extends Application {
private static AppComponent component;
@Override
public void onCreate() {
super.onCreate();
component = DaggerAppComponent.create();
}
public static AppComponent getComponent() {
return component;
}
}
AppComponent
@Component(modules = {MainActivityPresenterModule.class})
public interface AppComponent {
void injectMainActivity(MainActivity mainActivity);
}
MainActivityPresenterModule
@Module
public class MainActivityPresenterModule {
@Provides
MainActivityPresenter provideActivityPresenter(NetworkUtils networkUtils) {
return new MainActivityPresenter(networkUtils);
}
@Provides
NetworkUtils provideNetworkUtils(){
return new NetworkUtils();
}
}
NetworkUtils
public class NetworkUtils {
public boolean isConnection() {
return true;
}
}
MainActivityPresenter
public class MainActivityPresenter {
NetworkUtils networkUtils;
public MainActivityPresenter(NetworkUtils networkUtils) {
this.networkUtils = networkUtils;
}
public void getUser(){
if(networkUtils.isConnection()) {
Log.e("getUser", "getUser");
} else {
Log.e("no internet", "no internet connection");
}
}
}
MainActivity
public class MainActivity extends AppCompatActivity {
@Inject
MainActivityPresenterModule mainActivityPresenterModule;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
App.getComponent().injectMainActivity(MainActivity.this);
}
}