Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

How do you use dagger 2 injection with Moxy #18

Closed
maruf89 opened this issue Sep 20, 2016 · 9 comments
Closed

How do you use dagger 2 injection with Moxy #18

maruf89 opened this issue Sep 20, 2016 · 9 comments

Comments

@maruf89
Copy link

maruf89 commented Sep 20, 2016

Trying to use the @InjectPresenter in the Views and @InjectViewState preceding the presenter classes but my presenter classes also need to inject modules of their own which I'm doing via the constructor but I get this error

java.lang.RuntimeException: Unable to start activity ComponentInfo{com.jackthreads.android/com.jackthreads.android.activities.PageActivity}: java.lang.IllegalStateException: Unable to instantiate class com.jackthreads.android.presenters.PagePresenter: make sure class name exists, is public, and has an empty constructor that is public
     at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2661)
     at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2726)
     at android.app.ActivityThread.access$900(ActivityThread.java:172)
     at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1421)
     at android.os.Handler.dispatchMessage(Handler.java:102)
     at android.os.Looper.loop(Looper.java:145)
     at android.app.ActivityThread.main(ActivityThread.java:5835)
     at java.lang.reflect.Method.invoke(Native Method)
     at java.lang.reflect.Method.invoke(Method.java:372)
     at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:1399)
     at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:1194)
  Caused by: java.lang.IllegalStateException: Unable to instantiate class com.jackthreads.android.presenters.PagePresenter: make sure class name exists, is public, and has an empty constructor that is public
     at com.arellomobile.mvp.DefaultPresenterFactory.createPresenter(DefaultPresenterFactory.java:30)
     at com.arellomobile.mvp.DefaultPresenterFactory.createPresenter(DefaultPresenterFactory.java:11)
     at com.arellomobile.mvp.MvpProcessor.getMvpPresenter(MvpProcessor.java:125)
     at com.arellomobile.mvp.MvpProcessor.getMvpPresenters(MvpProcessor.java:177)
     at com.arellomobile.mvp.MvpDelegate.onCreate(MvpDelegate.java:110)
     at com.jackthreads.android.activities.MvpAppCompatActivity.onCreate(MvpAppCompatActivity.java:15)

Searching Moxy and Dagger 2 brings up nothing and it seems like they're messing each other up.

@senneco
Copy link
Collaborator

senneco commented Sep 20, 2016

Moxy says that it can't to instantiate class com.jackthreads.android.presenters.PagePresenter. Are sure class is public, and has an empty constructor that is public?

You could make gist, then I can help you ;)

@senneco
Copy link
Collaborator

senneco commented Sep 20, 2016

Here you can see, ho to use injection in presenter class.

@senneco senneco closed this as completed Sep 20, 2016
@senneco senneco reopened this Sep 20, 2016
@maruf89
Copy link
Author

maruf89 commented Sep 22, 2016

The problem I was having after injecting like in your example was that I was getting uninstantiated injected objects. In other cases I got an error from MvpAppCompatActivity crashing at getMvpDelegate due to super class instantiation errors. I realize that doesn't help much until I get a code sample up. Unfortunately I had to move forward without using Moxy InjectPresenter/ViewState annotations as I couldn't get it working I'll post something up when I get a chance.

@senneco
Copy link
Collaborator

senneco commented Sep 30, 2016

Sorry, but I don't understand. Are you need help?

@morder
Copy link

morder commented Feb 21, 2017

It's very unuseful to inject objects without constructor like this

@Inject
public ProfilePresenter(DataR dataR, MainN n, AuthM authM, BroadcastM broadcastM) {
}

because we need to call
YourApplication.getComponent().inject(this);
but we have complex dagger2 structure with many modules

@morder
Copy link

morder commented Feb 22, 2017

It will be good to inject presenters by some call in views, like

MvpFacade.getInstance().getMvpProcessor().addPresenter(View view, Presenter presenter,
PresenterType type);

@senneco
Copy link
Collaborator

senneco commented Feb 22, 2017

No, it's wrong way for inject presenter. You can use @ProvidePresenter to provide your Presenter's instance. See more about this here and here.

@morder
Copy link

morder commented Feb 22, 2017

Thanks, it's helps :)

@vkotovv
Copy link

vkotovv commented Jun 19, 2019

Related question - #100

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

4 participants