Skip to content
This repository has been archived by the owner on Aug 26, 2021. It is now read-only.

No injectable members on com.actionbarsherlock.app.SherlockFragmentActivity #74

Closed
luisdelarosa opened this issue Oct 25, 2012 · 13 comments

Comments

@luisdelarosa
Copy link

I'm trying to use Dagger with ActionBarSherlock 4.2.0.

I'm getting this error:

Caused by: java.lang.IllegalStateException: Errors creating object graph:
No injectable members on com.actionbarsherlock.app.SherlockFragmentActivity. Do you want to add an injectable constructor?
at dagger.internal.RuntimeLinker.reportErrors(RuntimeLinker.java:55)
at dagger.internal.Linker.linkRequested(Linker.java:114)
at dagger.ObjectGraph.getEntryPointBinding(ObjectGraph.java:247)
at dagger.ObjectGraph.inject(ObjectGraph.java:229)
at com.luisdelarosa.MyApplication.inject(MyApplication.java:38)

This worked fine with a regular FragmentActivity. How can I fix this?
Thanks!

@pforhan
Copy link
Contributor

pforhan commented Oct 25, 2012

Are you instantiating one of these directly, or are you subclassing? And this almost looks like you are using Dagger to construct an activity, which flies in the face of Android...

@luisdelarosa
Copy link
Author

Subclassing.

Sorry - I cut off the error message, so perhaps that will give a better clue. Here's the full message:

Caused by: java.lang.IllegalStateException: Errors creating object graph:
No injectable members on com.actionbarsherlock.app.SherlockFragmentActivity. Do you want to add an injectable constructor? required by members/com.luisdelarosa.MyApplication.MyActivity

MyActivity looks like:

public class MyActivity extends SherlockFragmentActivity {
    @Inject MyStore store;

    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        ((MyApplication) getApplication()).inject(this);
         // more work here
    }
}

Also, MyActivity is declared as an entryPoint.

@luisdelarosa
Copy link
Author

I just pulled and merged the latest upstream master and got a different exception:

Caused by: java.lang.IllegalStateException: Errors creating object graph:
No available @Inject handlers could be found for key members/com.actionbarsherlock.app.SherlockFragmentActivity in class com.actionbarsherlock.app.SherlockFragmentActivity required by members/com.luisdelarosa.MyActivity
at dagger.internal.ThrowingErrorHandler.handleErrors(ThrowingErrorHandler.java:34)
at dagger.internal.Linker.linkRequested(Linker.java:123)
at dagger.ObjectGraph.getEntryPointBinding(ObjectGraph.java:214)
at dagger.ObjectGraph.inject(ObjectGraph.java:196)
at com.luisdelarosa.MyApplication.inject(MyApplication.java:38)
at com.luisdelarosa.MyActivity.onCreate(MyActivity.java:26)
at android.app.Activity.performCreate(Activity.java:5008)
at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1079)
at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2023)

Then I added an explicit constructor in SherlockFragmentActivity.

@Inject
public SherlockFragmentActivity() {
}

This explicit constructor fixes these errors. I'd like to understand better why this would be required, though. I assume this isn't normal ABS/Dagger integration.
Thanks.

@pforhan
Copy link
Contributor

pforhan commented Oct 25, 2012

Generally, something must have an @Inject in it somewhere to function. However, it does not need that for super classes.

What you have looks pretty good. @swankjesse, any thoughts?

And just a sanity check, you're not @injecting an activity anywhere, are you?

@cgruber
Copy link
Collaborator

cgruber commented Oct 25, 2012

If you got the no at inject provider could be found that probably means you
didn't have anything @Inject marked so the code gen has no way to know to
create an adapter for it, and the reflection based handler has nothing
marked to look up.

You need to add an @Inject constructor or field(s).

Regards,
Christian
Sent from my iPhone.

On Oct 25, 2012, at 18:32, Patrick Forhan notifications@github.com wrote:

Generally, something must have an @Inject https://github.com/Inject in
it somewhere to function. However, it does not need that for super classes.

What you have ooks pretty good. @swankjesse https://github.com/swankjesse,
any thoughts?

And just a sanity check, you're not @injecting an activity anywhere, are
you?


Reply to this email directly or view it on
GitHubhttps://github.com//issues/74#issuecomment-9796832.

@pforhan
Copy link
Contributor

pforhan commented Oct 25, 2012

@cgruber FYI, in the 3rd comment, he shows an @Inject Store myStore; member in his activity class.

@cgruber
Copy link
Collaborator

cgruber commented Oct 25, 2012

Sorry. Missed it. Reading on my phone.

Upon further thought, I don't think we process annotations on superclasses
currently. I recall a getDeclaredConstructors() call (vaguely from
memory). We need to decide how we want to handle @Inject on parent types
if there are no local members that are annotated.

Regards,
Christian
Sent from my iPhone.

On Oct 25, 2012, at 18:51, Patrick Forhan notifications@github.com wrote:

@cgruber https://github.com/cgruber FYI, in the 3rd comment, he shows an
@Inject https://github.com/Inject Store myStore; member in his activity
class.


Reply to this email directly or view it on
GitHubhttps://github.com//issues/74#issuecomment-9797359.

@pforhan
Copy link
Contributor

pforhan commented Oct 29, 2012

@cgruber, did you ever look at this again? The way I understand it, this wasn't about annotations on super classes, it was a confusing message Dagger was giving out about a library superclass -- @Inject was in the subclass, but Dagger was complaining that the super class didn't have any @Injected members.

We do this with no issue (even the extending of SherlockFragmentActivity), but I don't know if there is some magic combination that @luisdelarosa is hitting upon.

@cgruber
Copy link
Collaborator

cgruber commented Oct 29, 2012

On 29 Oct 2012, at 11:16, Patrick Forhan wrote:

@cgruber, did you ever look at this again? The way I understand it,
this wasn't about annotations on super classes, it was a confusing
message Dagger was giving out about a library superclass -- @Inject
was in the subclass, but Dagger was complaining that the super class
didn't have any @Injected members.

We do this with no issue (even the extending of
SherlockFragmentActivity), but I don't know if there is some magic
combination that @luisdelarosa is hitting upon.

Hadn't gotten to it. I'll dig into it today and/or tomorrow.

c.

@swankjesse
Copy link
Contributor

Found it & fixed it. #84

@wombleabroad
Copy link

Not sure whether or not to create a new issue here, but this fix works fine when using the reflection strategy. Using 0.9 artifcacts, if I switch to the code generation strategy (by adding the dagger-compiler plugin dependency) I get the following error at runtime:

java.lang.IllegalStateException: Errors creating object graph:
No injectable members on com.actionbarsherlock.app.SherlockFragmentActivity. Do you want to add an injectable constructor? required by class com.foo.MyActivity
at dagger.internal.ThrowingErrorHandler.handleErrors(ThrowingErrorHandler.java:34)
at dagger.internal.Linker.linkRequested(Linker.java:136)
at dagger.ObjectGraph.getEntryPointBinding(ObjectGraph.java:264)
at dagger.ObjectGraph.inject(ObjectGraph.java:238)
at com.foo.MyActivity.onCreate(MyActivity.java:n)

I noticed that in MyActivity$InjectAdapter, the supertype instance field is set like this in the attach method:

supertype = (dagger.internal.Binding<com.actionbarsherlock.app.SherlockFragmentActivity>) linker.requestBinding("members/com.actionbarsherlock.app.SherlockFragmentActivity", com.foo.MyActivity.class);

The two argument Linker.requestBinding method calls the three argument Linker.requestBinding method with mustBeInjectable = true. Could this be the source of the error?

@swankjesse
Copy link
Contributor

Really fixed this with #102.

We didn't catch this in our own apps 'cause we accidentally disabled dagger-compiler when that code was split from the main module. We're running it now. That explains why I didn't see it.

Thanks!

@cgruber
Copy link
Collaborator

cgruber commented Nov 11, 2012

On 11 Nov 2012, at 18:31, Jesse Wilson wrote:

We didn't catch this in our own apps 'cause we accidentally disabled
dagger-compiler when that code was split from the main module. We're
running it now. That explains why I didn't see it.

Good test on #102, btw, Jesse.

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

No branches or pull requests

5 participants