title: I don't understand, why i get the error "java.lang.NullPointerException" instead "MainActivity: onCreate: test +1", and how to fix it?
body: <p>Help me understand, why i get the error "java.lang.NullPointerException" instead "MainActivity: onCreate: test +1", and how to fix it?</p>
  
  <p>My code is bellow:</p>
  
  <pre><code>//App.java
  public class App extends Application implements HasAndroidInjector {
      @Inject DispatchingAndroidInjector&lt;Object&gt; dispatchingAndroidInjector;
  
      @Module(includes = {AndroidSupportInjectionModule.class})
      interface AppModule {
          @ContributesAndroidInjector(modules = {ActivityModule.class})
          MainActivity provideActivity();
      }
  
      @Component(modules = {AppModule.class})
      interface AppComponent {
          void inject(App app);
      }
  
      @Override
      public void onCreate() {
          super.onCreate();
          DaggerApp_AppComponent.create().inject(this);
      }
  
      @Override
      public AndroidInjector&lt;Object&gt; androidInjector() {
          return dispatchingAndroidInjector;
      }
  }
  
  </code></pre>
  
  <pre><code>//ActivityModule.java
  @Module
      class ActivityModule {
          @Provides
          Base provideBase(){
              return new Base("test");
          }
      }
  </code></pre>
  
  <pre><code>//MainActivity.java
  public class MainActivity extends AppCompatActivity {
  
      @Inject Base mBase;
      @Override
      protected void onCreate(Bundle savedInstanceState) {
          AndroidInjection.inject(this);
          super.onCreate(savedInstanceState);
          setContentView(R.layout.activity_main);
          Log.d("MainActivity", "onCreate: " + mBase.getString());
      }
  }
  </code></pre>
  
  <pre><code>//Base.java
  public class Base {
  
      private String mString;
  
      public Base(String string) {
          mString = string;
      }
  
      public String getString() {
          return mString;
      }
  }
  </code></pre>
  
  <p>Result is Ok: "MainActivity: onCreate: test", but if i add subclass in Base.class, i get error</p>
  
  <pre><code>//SubBase.java
  public class SubBase {                        //&lt;- add
                                                //&lt;- add
      private String mString;                   //&lt;- add
                                                //&lt;- add
      public SubBase(String string) {           //&lt;- add
          mString = string;                     //&lt;- add
      }                                         //&lt;- add
                                                //&lt;- add
      public String getString() {               //&lt;- add
          return mString;                       //&lt;- add
      }                                         //&lt;- add
  }                                             //&lt;- add
  </code></pre>
  
  <pre><code>//Base.java
  public class Base {
  
      private String mString;
      @Inject SubBase mSubBase;                 //&lt;- add
  
      public Base(String string) {
          mString = string;
      }
  
      public String getString() {
          return mString+mSubBase.getString();  //&lt;- change
      }
  }
  </code></pre>
  
  <pre><code>//ActivityModule.java
  @Module
  class ActivityModule {
      @Provides
      Base provideBase(){
          return new Base("test");
      }
  
      @Provides                                 //&lt;- add
      SubBase provideSubBase() {                //&lt;- add
          return new SubBase(" +1");            //&lt;- add
      }
  }
  </code></pre>
  
  <p>Result Error: "java.lang.NullPointerException", but i expected "MainActivity: onCreate: test +1"`</p>
  
  <p><strong>UPDATE1</strong>
  I don’t want to do this:</p>
  
  <pre><code>//ActivityModule.java
  @Module
  class ActivityModule {
      @Provides
      SubBase provideSubBase() {
          return new SubBase(" +1");
      }
  
      @Provides
      Base provideBase(SubBase subBase){          //&lt;- change
          return new Base("test", subBase);       //&lt;- change
      }
  
  }
  </code></pre>
  
  <pre><code>//Base.java
  public class Base {
  
      private String mString;
      private SubBase mSubBase;                           //&lt;- add
  
      public Base(String string, SubBase subBase) {       //&lt;- change
          mString = string;
          mSubBase = subBase;                             //&lt;- add 
      }
  
  
      public String getString() {
          return mString + mSubBase.getString();
      }
  }
  </code></pre>
  
  <p><strong>UPDATE2</strong> full stack trace</p>
  
  <pre><code>    E/AndroidRuntime: FATAL EXCEPTION: main
      Process: io.softline.dagger, PID: 14071
      java.lang.RuntimeException: Unable to start activity ComponentInfo{io.softline.dagger/io.softline.dagger.MainActivity}: java.lang.NullPointerException: Attempt to invoke virtual method 'java.lang.String io.softline.dagger.SubBase.getString()' on a null object reference
          at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2665)
          at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2726)
          at android.app.ActivityThread.-wrap12(ActivityThread.java)
          at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1477)
          at android.os.Handler.dispatchMessage(Handler.java:102)
          at android.os.Looper.loop(Looper.java:154)
          at android.app.ActivityThread.main(ActivityThread.java:6119)
          at java.lang.reflect.Method.invoke(Native Method)
          at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:886)
          at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:776)
       Caused by: java.lang.NullPointerException: Attempt to invoke virtual method 'java.lang.String io.softline.dagger.SubBase.getString()' on a null object reference
          at io.softline.dagger.Base.getString(Base.java:24)
          at io.softline.dagger.MainActivity.onCreate(MainActivity.java:36)
          at android.app.Activity.performCreate(Activity.java:6679)
          at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1118)
          at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2618)
          at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2726) 
          at android.app.ActivityThread.-wrap12(ActivityThread.java) 
          at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1477) 
          at android.os.Handler.dispatchMessage(Handler.java:102) 
          at android.os.Looper.loop(Looper.java:154) 
          at android.app.ActivityThread.main(ActivityThread.java:6119) 
          at java.lang.reflect.Method.invoke(Native Method) 
          at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:886) 
          at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:776) 
  </code></pre>
  
  <p>The error is simple: the variable is not initialized. Judging by the generated code, the Base_MembersInjector class is not called if the Base class constructor (SubBase mSubBase) is not used. How to force dagger to inject in a field?</p>