title: Using Assisted Inject with FactoryModuleBuilder in guice - Factory injection not being done
body: <p>I am a guice newbie trying to figure out how to implement assisted inject in the guice using FactoryModuleBuilder. I consulted the guice java docs for implementing <a href="http://google-guice.googlecode.com/git/javadoc/com/google/inject/assistedinject/FactoryModuleBuilder.html" rel="nofollow noreferrer">FactoryModuleBuilder</a>.</p>
  
  <p>I have done everything exactly as it says in the docs. 
  Its not injecting the factory. 
  I referred to this stack overflow question :<a href="https://stackoverflow.com/questions/14760219/guice-assistedinject-wont-inject-the-factory">Guice AssistedInject won't inject the factory</a>
  which had the same problem. 
  It talks about the field injection before constructor injection problem. I followed it  and I am trying to call the Parent class using a caller class but I am still getting the null pointer exception. What is going wrong here?</p>
  
  <p><b>Caller class</b></p>
  
  <pre><code>public class MAIN {
  
      @Inject private static MyFactory factory;
  
      public static void main(String[] args){
          ParentClass newbie = new ParentClass(factory);
      }
  }
  </code></pre>
  
  <p>I am still getting the exception:</p>
  
  <pre><code>Exception in thread "main" java.lang.NullPointerException
      at com.pkg.ParentClass.&lt;init&gt;(ParentClass.java:19)
      at com.pkg.MAIN.main(MAIN.java:10)
  </code></pre>
  
  <p><b> Parent Class</b></p>
  
  <pre><code>public class ParentClass {
  
      private final Foo test;
      @Inject
      public ParentClass(MyFactory factory){
          test = factory.create(new HashMap&lt;String,Object&gt;());
      }
  }
  </code></pre>
  
  <p><b>Module Implementation: ParentModule</b></p>
  
  <pre><code>public class ParentModule extends AbstractModule{
  
      @Override
      protected void configure() {
          install(new FactoryModuleBuilder()
                  .implement(Foo.class, FooImpl.class)
                  .build(MyFactory.class));
      }
  
  }
  </code></pre>
  
  <p><b>Factory Interface: MyFactory</b></p>
  
  <pre><code>public interface MyFactory {
  
      Foo create(Map&lt;String,Object&gt; map);
  }
  </code></pre>
  
  <p><b>Class Interface : Foo</b></p>
  
  <pre><code>public interface Foo{
  }
  </code></pre>
  
  <p><b>Class:FooImpl</b></p>
  
  <pre><code>public class FooImpl implements Foo {
  
      private final Map&lt;String,Object&gt; mapA;
      @AssistedInject
      public FooImpl(@Assisted Map&lt;String,Object&gt; map){
  
          mapA=map;
      }
  
  }
  </code></pre>