title: Application crash with “android.app.Application cannot be cast to”
body: <p>I'm disovering ORMlite. So, I have this DAO Factory class </p>
  
  <pre><code>public class DtoFactory extends Application {
  
      private SharedPreferences preferences;
      private DatabaseHelper databaseHelper = null;
  
      private Dao&lt;ReleveEntity, Integer&gt; releveDAO = null;
  
      @Override
      public void onCreate() {
              super.onCreate();
              preferences = PreferenceManager.getDefaultSharedPreferences(this);
              databaseHelper = new DatabaseHelper(this);
      }
  
      public SharedPreferences getPreferences() {return preferences;}
  
      public Dao&lt;ReleveEntity, Integer&gt; getReleveDao() throws SQLException, java.sql.SQLException {
              if (releveDAO == null) {
                  releveDAO = databaseHelper.getDao(ReleveEntity.class);
              }
              return releveDAO;
      }
  
      @Override
      public void onTerminate() {
              super.onTerminate();
              if (databaseHelper != null) {
                      OpenHelperManager.releaseHelper();
                      databaseHelper = null;
              }
      }
  } 
  </code></pre>
  
  <p>And in the Main, I'll show just this lines where I have the problem :</p>
  
  <pre><code> @Override
  public void onCreate(Bundle savedInstanceState) {
      super.onCreate(savedInstanceState);
      setContentView(R.layout.main);
      dtoFactory = (DtoFactory) getApplication();
  </code></pre>
  
  <p>And the manifest.xml</p>
  
  <pre><code>   &lt;application
      android:allowBackup="true"
      android:icon="@drawable/ic_launcher"
      android:label="@string/app_name"
      android:theme="@style/AppTheme" &gt;
      &lt;activity
          android:name="com.exercice.ftouzi.ReleveActivity"
          android:label="@string/app_name" &gt;
          &lt;intent-filter&gt;
              &lt;action android:name="android.intent.action.MAIN" /&gt;
  
              &lt;category android:name="android.intent.category.LAUNCHER" /&gt;
          &lt;/intent-filter&gt;
      &lt;/activity&gt;
      &lt;activity android:name="com.exercice.ormdatabase.DtoFactory" &gt;
      &lt;/activity&gt;
  &lt;/application&gt;
  </code></pre>
  
  <p>The message error is :</p>
  
  <pre><code> E/AndroidRuntime(19672): FATAL EXCEPTION: main
   E/AndroidRuntime(19672): java.lang.RuntimeException: Unable to start activity
        ComponentInfo{com.formation.adapter/com.exercice.ftouzi.ReleveActivity}: 
        java.lang.ClassCastException: android.app.Application cannot be cast to
        com.exercice.ormdatabase.DtoFactory
  </code></pre>
  
  <p>Can you please help me to resolve this ?</p>