title: Using Dagger2 with Database
body: <p>I am trying to use dagger2 and database in my android application. I can not access the database class with the inject operation. The Database db object I created is returning null. I am new on dagger2. Thanks for any help.</p>
  
  <p>This is my database class.</p>
  
  <pre><code>public  class Database extends SQLiteOpenHelper {
  
  
  @Inject
  public Database(@ApplicationContext Context context) {
      super(context, Constants.DATABASE_NAME, null, Constants.DATABASE_VERSION);
  }
  
  public void createTables(){..}
  
  public void clearAllTables() {...}
  
  public void dropTable(SQLiteDatabase db, String tableName){
      db.execSQL("DROP TABLE IF EXISTS " + tableName);
  }
  
  @Override
  public void onCreate(SQLiteDatabase db) {.. }  .. }
  </code></pre>
  
  <p>This is my module.</p>
  
  <pre><code>@Module abstract public class DatabaseModule {
  
  private Application application;
  public DatabaseModule(Application application) {
      this.application = application;
  }
  @Provides
  @ApplicationContext
  Context provideContext() {
      return application;
  }}
  </code></pre>
  
  <p>And component</p>
  
  <pre><code>@ActivityScope @Subcomponent public interface DatabaseSubcomponent {
  
  @ApplicationContext
  Context getContext();
  
  Database getDb(); }
  </code></pre>
  
  <p>Db object returns null as follows :</p>
  
  <pre><code>   @Inject
  Database db;
  </code></pre>
  
  <p>I will be grateful if you tell me where I made a mistake. Thanks in advance.</p>