Roboguice: using manual injections causes ConfigurationException (no implementation was bound)

137 views Asked by At

I've found an issue with Roboguice when using manual instance resolution. It works once I turn off the Annotation Database. Otherwise I get the exception:

No implementation for com.kmsoftware.roboguicetest.SomeInterface was bound.

Am I doing something wrong or is it just a Robolectric/Roboblender bug?

The code looks like this:

MainActivity.java

public class MainActivity extends RoboActionBarActivity {

//    static {
//        RoboGuice.setUseAnnotationDatabases(false);
//    }

    @Inject
    FragmentManager fragmentManager;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);


        TextView tv = (TextView) findViewById(R.id.activityMainLabel);

        SomeInterface instance = RoboGuice.getInjector(this).getInstance(SomeInterface.class);

        tv.setText(String.valueOf(instance.getValue()));
    }

    ...
}

RoboModule.java

public class RoboModule extends AbstractModule {
    @Override
    protected void configure() {

        bind(SomeInterface.class).to(ConcreteClass.class);
    }
}

SomeInterface.java

public interface SomeInterface {
    int getValue();
}

ConcreteClass.java

public class ConcreteClass implements SomeInterface {
    @Override
    public int getValue() {
        return 7;
    }
}
0

There are 0 answers