0
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.
--
You received this message because you are subscribed to the Google Groups
"google-guice" group.
To unsubscribe from this group and stop receiving emails from it, send an email
to [email protected].
To post to this group, send email to [email protected].
Visit this group at https://groups.google.com/group/google-guice.
To view this discussion on the web visit
https://groups.google.com/d/msgid/google-guice/b8693e5d-06ba-4364-8f94-1e0051576311%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.