Am trying to learn google juice. I have a InstallConfigurationModule class which has all the dependency needed to create an object of typeA and TypeB .And, got a class say class Car as shown Below and am trying to do constructor injection. When the run method is called am getting null pointer exception at system.out.println line. I know for sure that ModuleA, ModuleB has a reference on creating TypeA, TypeB since in my InstallConfigurationModulemodule, if I say Bind(TypeA.class)or Bind(TypeB.class), I get google juice error, 'A binding to typeA or typeB already configured'.
public class InstallConfigurationModule extends AbstractModule {
@Override
protected void configure() {
install(new ModuleA());
install(new ModuleB());
}
}
public class Car
{
private Type A;
private Type B;
@inject
void SetCar(Type A, Type B)//not the constructor
{
this.A=A;
this.B=B;
}
private void run()
{
System.out.println(A.toString()) //throw null pointer exception
}
what Worked:
private void run()
{
Injector injector = Guice.createInjector(new
InstallConfigurationModule());
TypeA typeA =injector.getInstance(TypeA.class);
System.out.println(A.toString()) //works fine
}
Why do I get NPE when I try to do without creatingInjector. Any help appreciated.
PS: very new to juice.
Caused by: java.lang.NoSuchMethodException:com.example.car.ToString().