title: try to get Retrofit with dependency injection
body: <p>I am trying to get List of job leads in my android application.I use Dagger 2 with Retrofit and OkHttp,But I get this error</p>
  <pre><code>java.lang.RuntimeException: Unable to start activity ComponentInfo{com.../com...AccueilActivity}: java.lang.NullPointerException: Attempt to invoke virtual method 'java.lang.Object retrofit2.Retrofit.create(java.lang.Class)' on a null object reference
                                                                        at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:3319)
                                                                        at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:3415)
                                                                        at android.app.ActivityThread.access$1100(ActivityThread.java:229)
                                                                        at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1821)
                                                                        at android.os.Handler.dispatchMessage(Handler.java:102)
                                                                        at android.os.Looper.loop(Looper.java:148)
                                                                        at android.app.ActivityThread.main(ActivityThread.java:7325)
                                                                        at java.lang.reflect.Method.invoke(Native Method)
                                                                        at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:1230)
                                                                        at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:1120)
                                                                     Caused by: java.lang.NullPointerException: Attempt to invoke virtual method 'java.lang.Object retrofit2.Retrofit.create(java.lang.Class)' on a null object reference
  </code></pre>
  <p>I create two components ApplicationComponent, NetComponent</p>
  <pre><code>@Singleton
  @Component(modules = {NetModule.class,ApplicationModule.class})
  public interface NetComponent {
      void inject(AppCompatActivity activity);
      void inject(Fragment fragment);
  }
  </code></pre>
  <p>and Tow modules ApplicationModule, NetModule</p>
  <pre><code>import android.app.Application;
  import dagger.Module;
  import dagger.Provides;
  import okhttp3.Cache;
  import okhttp3.OkHttpClient;
  import retrofit2.Retrofit;
  import retrofit2.converter.gson.GsonConverterFactory;
  import com.google.gson.FieldNamingPolicy;
  import com.google.gson.Gson;
  import com.google.gson.GsonBuilder;
  import javax.inject.Singleton;
      
  @Module
  public class NetModule {
      String baseUrl;
      
      public NetModule(String baseUrl) {
          this.baseUrl = baseUrl;
      }
      
      @Provides
      @Singleton
      Cache provideOkHttpCache(Application application) {
          int cacheSize = 10 * 1024 * 1024; // 10 MiB
          Cache cache = new Cache(application.getCacheDir(), cacheSize);
          return cache;
      }
      
      @Provides
      @Singleton
      Gson provideGson() {
          GsonBuilder gsonBuilder = new GsonBuilder();
          gsonBuilder.setFieldNamingPolicy(FieldNamingPolicy.LOWER_CASE_WITH_UNDERSCORES);
          return gsonBuilder.create();
      }
  
      @Provides
      @Singleton
      OkHttpClient provideOkHttpClient(Cache cache) {
          OkHttpClient client = new OkHttpClient.Builder().cache(cache).build();
          return client;
      }
      
      @Provides
      @Singleton
      public Retrofit provideRetrofit(Gson gson, OkHttpClient okHttpClient) {
          Retrofit retrofit = new Retrofit.Builder()
                  .addConverterFactory(GsonConverterFactory.create(gson))
                  .baseUrl(baseUrl)
                  .client(okHttpClient)
                  .build();
          return retrofit;
      }
  }
  </code></pre>
  <p>I try to inject the Retrofit in my Activity but i get null exception</p>
  <pre><code>public class AccueilActivity extends AppCompatActivity {
      ArrayList&lt;MenuItem&gt; menu = new ArrayList&lt;&gt;();   
      @Inject
      Retrofit retrofit;
      
      @Override
      protected void onCreate(Bundle savedInstanceState) {
          super.onCreate(savedInstanceState);
          setContentView(R.layout.activity_accueil);
          ((AndroidApplication) getApplicationContext()).getNetComponent().inject(this);
          Call&lt;List&lt;JobLeads&gt;&gt; jobLeadList = retrofit.create(GetJobLeads.class).getJobLeads();
          jobLeadList.enqueue(new Callback&lt;List&lt;JobLeads&gt;&gt;() {
                  @Override
                  public void success(Result&lt;List&lt;JobLeads&gt;&gt; result) {
                  }
  
                  @Override
                  public void failure(TwitterException exception) {
                  }
          });
      }
  </code></pre>
  <p>and this is AndroidApplication class</p>
  <pre><code>public class AndroidApplication extends Application {
      private ApplicationComponent applicationComponent;
      private NetComponent netComponent;
  
      @Override
      public void onCreate() {
          super.onCreate();
          this.initializeInjector();
          SugarContext.init(this);
      }
     
      private void initializeInjector() {
          this.applicationComponent = DaggerApplicationComponent.builder()
                  .applicationModule(new ApplicationModule(this))
                  .build();
          this.netComponent = DaggerNetComponent.builder()
                  .applicationModule(new ApplicationModule(this))
                  .netModule(new NetModule(JOB_LEADS_API2))
                  .build();
      }
  
      public ApplicationComponent getApplicationComponent() {
          return this.applicationComponent;
      }
  
      public NetComponent getNetComponent() {
          return this.netComponent;
      }
  
      @Override
      public void onTerminate() {
          super.onTerminate();
          SugarContext.terminate();
      }
  }
  </code></pre>