我在使用手动实例解析时遇到了Roboguice的问题。一旦我关闭注释数据库,它就可以工作。否则我得到例外:
No implementation for com.kmsoftware.roboguicetest.SomeInterface was bound.
我做错了什么还是仅仅是Robolectric / Roboblender的错误?
代码如下所示:
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;
}
}