A binding already exists on a child injector error?

483 views
Skip to first unread message

glenviewjeff

unread,
Jul 15, 2011, 4:09:55 PM7/15/11
to google...@googlegroups.com
I'm trying to implement the solution to the "robot legs" problem and solution described in the FAQ, but received the following very unclear error.  I am not aware of any explicit use in my application of "child injectors."

Thanks for any help!

1) A binding to ...myClass<..myOtherClass> already exists on a child injector.
  while locating ...myClass<..myOtherClass>
    for parameter 0 at ...AnotherClass.<init>(Unknown Source)
  while locating ...AnotherClass
    for parameter 2 at ...YetAnotherClass.<init>(Unknown Source)
  while locating YetAnotherClass
    for parameter 2 at ...EvenAnotherClass.<init>(Unknown Source)
  at ...LastClass(MyModule.java:65)

Sam Berlin

unread,
Jul 15, 2011, 4:10:26 PM7/15/11
to google...@googlegroups.com
Upgrade to Guice 3.0 -- it gives a more descriptive error message.

sam


--
You received this message because you are subscribed to the Google Groups "google-guice" group.
To view this discussion on the web visit https://groups.google.com/d/msg/google-guice/-/W3NTM0VUdVoJ.
To post to this group, send email to google...@googlegroups.com.
To unsubscribe from this group, send email to google-guice...@googlegroups.com.
For more options, visit this group at http://groups.google.com/group/google-guice?hl=en.

glenviewjeff

unread,
Jul 15, 2011, 4:23:35 PM7/15/11
to google...@googlegroups.com
Unfortunately, this isn't possible, as I am using Roboguice for Android, which at present is based on 2.0.  If this is of any additional value, the line that I'm receiving the error on is a multibinder:

Multibinder<Helper> helpers = Multibinder.newSetBinder(binder(), Helper.class, Stuff.class);
activityHelpers.addBinding().to(XYZ.class); // Fails on this line


Sam Berlin

unread,
Jul 15, 2011, 4:26:59 PM7/15/11
to google...@googlegroups.com
3.0 should be a drop-in replacement for 2.0 for the most part. It should work flawlessly with Roboguice.  Give it a shot.  The problem is that the binding was already added in a private module, and 3.0 will include in the error message exactly where and in which PrivateModule you've got the binding that you're also adding in the parent module.

sam

--
You received this message because you are subscribed to the Google Groups "google-guice" group.
To view this discussion on the web visit https://groups.google.com/d/msg/google-guice/-/EfaRLhhfpBsJ.

glenviewjeff

unread,
Jul 26, 2011, 12:58:48 PM7/26/11
to google...@googlegroups.com
I gave it a shot.  It doesn't appear Roboguice 1.1 is compatible with Guice, and others have reported the same.  1.2 is still under development (to support Guice 3.0).

When trying Guice 3.0, I got a NoClassDefFoundError when Roboguice is messing with custom scopes in its injector creation method (and yes, I did remember to add java.injectx jars to my projects.)

Jeff

glenviewjeff

unread,
Jul 27, 2011, 1:02:42 PM7/27/11
to google...@googlegroups.com
In the event anyone else runs into this binding error, the problem ended up that I was registering my private module more than once because I accidentally instantiated the private module both from the Guice.createInjector call as well as in my main module using what I believe is the recommended technique, by adding this line in my main module's configure() method:

install(new MyPrivateModule());

Jeff
Reply all
Reply to author
Forward
0 new messages