Navigation Menu

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

Inject class with no empty constructors from other module failed. #335

Open
baijianhua opened this issue Mar 3, 2016 · 0 comments
Open

Comments

@baijianhua
Copy link

Define a class like this, and inject it in classes, if this class is in the same app module, it will success, but if move this class to a library module, it will fail. Exception is:
com.google.inject.CreationException: Unable to create injector, see the following errors:

  1. Could not find a suitable constructor in com.lenovo.shareit.Test1. Classes must have either one (and only one) constructor annotated with @Inject or a zero-argument constructor that is not private.
    at com.lenovo.shareit.Test1.class(Unknown Source)
    while locating com.lenovo.shareit.Test1
    for field at com.lenovo.shareit.ShareitApp.test(Unknown Source)
    at roboguice.config.DefaultRoboModule.configure(DefaultRoboModule.java:166)

1 error

-----------------------------------------------------------source code being injected.
import com.google.inject.Inject;
import com.google.inject.name.Named;
import com.lenovo.shareit.common.EventBusToken;

import org.greenrobot.eventbus.EventBus;

/**

  • Created by Wallace on 3/3/2016.
    */
    public class Test {
    @Inject
    public Test(@nAmed(EventBusToken.Common)EventBus bus){
    System.out.println("bus="+bus);

    }
    public static void test1(){
    System.out.println("Test::test1::v2");
    }
    public void testNoneStatic(){
    System.out.println("Test::no static method::v1");
    }
    }

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

No branches or pull requests

1 participant