title: Android - java.lang.classcastexception android.app.application cannot be cast
body: <p>I'm an Android newbie, and I'm building an android app about tutorial and I want to include game features in it, I already have the source code for the game and i already import all the classes to my project, however when i try to run the app i got an error and it said &quot;android.app.application java.lang.ClassCastException can not be cast to com.wglxy.example.dash1.ChuckApplication&quot;, i assume that is because i fave 2 activity called HomeActivity.java (Main) and ChuckApplication.java (second) with different extend (DashboardActivity &amp; Application) i really do not know how to solve this, i've try</p>
  <ol>
  <li><p>Make the game application as library(not work)</p>
  </li>
  <li><p>Combine the activities (not work)</p>
  </li>
  <li><p>modify inten-filter &gt; category (not work)</p>
  <p>but there is nothing work with my project</p>
  </li>
  </ol>
  <p>SplashActivity.java:</p>
  <pre><code>    import java.io.IOException;
      import java.util.List;
      
      import android.app.Activity;
      import android.content.Intent;
      import android.content.SharedPreferences;
      import android.database.SQLException;
      import android.os.Bundle;
      import android.view.View;
      import android.view.View.OnClickListener;
      import android.widget.Button;
      
      import com.tmm.android.chuck.db.DBHelper;
      import com.tmm.android.chuck.quiz.Constants;
      import com.tmm.android.chuck.quiz.GamePlay;
      import com.tmm.android.chuck.quiz.Question;
      
      public class SplashActivity extends Activity implements OnClickListener{
      
          
          @Override
          public void onCreate(Bundle savedInstanceState) {
              super.onCreate(savedInstanceState);
              setContentView(R.layout.welcome);
      
              //////////////////////////////////////////////////////////////////////
              //////// GAME MENU  /////////////////////////////////////////////////
              Button playBtn = (Button) findViewById(R.id.playBtn);
              playBtn.setOnClickListener(this);
              Button settingsBtn = (Button) findViewById(R.id.settingsBtn);
              settingsBtn.setOnClickListener(this);
              Button rulesBtn = (Button) findViewById(R.id.rulesBtn);
              rulesBtn.setOnClickListener(this);
              Button exitBtn = (Button) findViewById(R.id.exitBtn);
              exitBtn.setOnClickListener(this);
          }
      
      
          /**
           * Listener for game menu
           */
          @Override
          public void onClick(View v) {
              Intent i;
              
              switch (v.getId()){
              case R.id.playBtn :
                  //once logged in, load the main page
                  //Log.d(&quot;LOGIN&quot;, &quot;User has started the game&quot;);
                  
                  //Get Question set //
                  List&lt;Question&gt; questions = getQuestionSetFromDb();
      
                  //Initialise Game with retrieved question set ///
                  GamePlay c = new GamePlay();
                  c.setQuestions(questions);
                  c.setNumRounds(getNumQuestions());
                  ((ChuckApplication)getApplication()).setCurrentGame(c);  
      
                  //Start Game Now.. //
                  i = new Intent(this, QuestionActivity.class);
                  startActivityForResult(i, Constants.PLAYBUTTON);
                  break;
                  
              case R.id.rulesBtn :
                  i = new Intent(this, RulesActivity.class);
                  startActivityForResult(i, Constants.RULESBUTTON);
                  break;
                  
              case R.id.settingsBtn :
                  i = new Intent(this, SettingsActivity.class);
                  startActivityForResult(i, Constants.SETTINGSBUTTON);
                  break;
                  
              case R.id.exitBtn :
                  finish();
                  break;
              }
      
          }
      
      
          /**
           * Method that retrieves a random set of questions from
           * the database for the given difficulty
           * @return
           * @throws Error
           */
          private List&lt;Question&gt; getQuestionSetFromDb() throws Error {
              int diff = getDifficultySettings();
              int numQuestions = getNumQuestions();
              DBHelper myDbHelper = new DBHelper(this);
              try {
                  myDbHelper.createDataBase();
              } catch (IOException ioe) {
                  throw new Error(&quot;Unable to create database&quot;);
              }
              try {
                  myDbHelper.openDataBase();
              }catch(SQLException sqle){
                  throw sqle;
              }
              List&lt;Question&gt; questions = myDbHelper.getQuestionSet(diff, numQuestions);
              myDbHelper.close();
              return questions;
          }
      
      
          /**
           * Method to return the difficulty settings
           * @return
           */
          private int getDifficultySettings() {
              SharedPreferences settings = getSharedPreferences(Constants.SETTINGS, 0);
              int diff = settings.getInt(Constants.DIFFICULTY, Constants.MEDIUM);
              return diff;
          }
      
          /**
           * Method to return the number of questions for the game
           * @return
           */
          private int getNumQuestions() {
              SharedPreferences settings = getSharedPreferences(Constants.SETTINGS, 0);
              int numRounds = settings.getInt(Constants.NUM_ROUNDS, 20);
              return numRounds;
          }
      
      }
  </code></pre>
  <p>this is my HomeActivity.java</p>
  <pre><code>/*
   * Copyright (C) 2011 Wglxy.com
   *
   * Licensed under the Apache License, Version 2.0 (the &quot;License&quot;);
   * you may not use this file except in compliance with the License.
   * You may obtain a copy of the License at
   *
   *      http://www.apache.org/licenses/LICENSE-2.0
   *
   * Unless required by applicable law or agreed to in writing, software
   * distributed under the License is distributed on an &quot;AS IS&quot; BASIS,
   * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
   * See the License for the specific language governing permissions and
   * limitations under the License.
   */
  package com.wglxy.example.dash1;
  
  import android.os.Bundle;
  
  /**
   * This is a simple activity that demonstrates the dashboard user interface
   * pattern.
   *
   */
  
  public class HomeActivity extends DashboardActivity
  {
  
      /**
       * onCreate - called when the activity is first created. Called when the
       * activity is first created. This is where you should do all of your normal
       * static set up: create views, bind data to lists, etc. This method also
       * provides you with a Bundle containing the activity's previously frozen
       * state, if there was one.
       *
       * Always followed by onStart().
       *
       */
  
      protected void onCreate(Bundle savedInstanceState)
      {
          super.onCreate(savedInstanceState);
          setContentView(R.layout.activity_home);
      }
  
      /**
       * onDestroy The final call you receive before your activity is destroyed.
       * This can happen either because the activity is finishing (someone called
       * finish() on it, or because the system is temporarily destroying this
       * instance of the activity to save space. You can distinguish between these
       * two scenarios with the isFinishing() method.
       *
       */
  
      protected void onDestroy()
      {
          super.onDestroy();
      }
  
      /**
       * onPause Called when the system is about to start resuming a previous
       * activity. This is typically used to commit unsaved changes to persistent
       * data, stop animations and other things that may be consuming CPU, etc.
       * Implementations of this method must be very quick because the next
       * activity will not be resumed until this method returns. Followed by
       * either onResume() if the activity returns back to the front, or onStop()
       * if it becomes invisible to the user.
       *
       */
  
      protected void onPause()
      {
          super.onPause();
      }
  
      /**
       * onRestart Called after your activity has been stopped, prior to it being
       * started again. Always followed by onStart().
       *
       */
  
      protected void onRestart()
      {
          super.onRestart();
      }
  
      /**
       * onResume Called when the activity will start interacting with the user.
       * At this point your activity is at the top of the activity stack, with
       * user input going to it. Always followed by onPause().
       *
       */
  
      protected void onResume()
      {
          super.onResume();
      }
  
      /**
       * onStart Called when the activity is becoming visible to the user.
       * Followed by onResume() if the activity comes to the foreground, or
       * onStop() if it becomes hidden.
       *
       */
  
      protected void onStart()
      {
          super.onStart();
      }
  
      /**
       * onStop Called when the activity is no longer visible to the user because
       * another activity has been resumed and is covering this one. This may
       * happen either because a new activity is being started, an existing one is
       * being brought in front of this one, or this one is being destroyed.
       *
       * Followed by either onRestart() if this activity is coming back to
       * interact with the user, or onDestroy() if this activity is going away.
       */
  
      protected void onStop()
      {
          super.onStop();
      }
  
      /**
       */
      // Click Methods
  
      /**
       */
      // More Methods
  
  } // end class
  </code></pre>
  <p>this is my ChuckApllicatiin:</p>
  <pre><code>/**
   *
   */
  package com.wglxy.example.dash1;
  
  import android.app.Application;
  
  /**
   * @author rob
   *
   */
  public class ChuckApplication extends Application
  {
      private GamePlay currentGame;
  
      /**
       * @param currentGame
       *            the currentGame to set
       */
      public void setCurrentGame(GamePlay currentGame)
      {
          this.currentGame = currentGame;
      }
  
      /**
       * @return the currentGame
       */
      public GamePlay getCurrentGame()
      {
          return currentGame;
      }
  }
  </code></pre>
  <p>this is my manifest.xml</p>
  <pre class="lang-xml prettyprint-override"><code>&lt;?xml version=&quot;1.0&quot; encoding=&quot;utf-8&quot;?&gt;
  &lt;manifest xmlns:android=&quot;http://schemas.android.com/apk/res/android&quot;
      package=&quot;com.wglxy.example.dash1&quot;
      android:versionCode=&quot;1&quot;
      android:versionName=&quot;1.0&quot; &gt;
      &lt;application
          android:icon=&quot;@drawable/icon&quot;
          android:label=&quot;@string/app_name&quot;
          android:theme=&quot;@style/Theme.D1&quot; &gt;
          &lt;activity
              android:name=&quot;.HomeActivity&quot;
              android:label=&quot;@string/app_name&quot; &gt;
              &lt;intent-filter&gt;
                  &lt;action android:name=&quot;android.intent.action.MAIN&quot; /&gt;
                  &lt;category android:name=&quot;android.intent.category.LAUNCHER&quot; /&gt;
              &lt;/intent-filter&gt;
          &lt;/activity&gt;
          &lt;activity
              android:name=&quot;.Tutorial&quot;
              android:label=&quot;@string/title_feature1&quot;
              android:theme=&quot;@style/Theme.D1&quot; /&gt;
          &lt;activity
              android:name=&quot;.Game&quot;
              android:label=&quot;@string/title_feature2&quot;
              android:theme=&quot;@style/Theme.D1&quot; /&gt;
          &lt;activity
              android:name=&quot;.Setting&quot;
              android:label=&quot;@string/title_feature3&quot;
              android:theme=&quot;@style/Theme.D1&quot; /&gt;
          &lt;activity
              android:name=&quot;.Qiblah&quot;
              android:label=&quot;@string/title_feature4&quot;
              android:theme=&quot;@style/Theme.D1&quot; /&gt;
          &lt;activity
              android:name=&quot;.Takbir&quot;
              android:label=&quot;@string/title_feature5&quot;
              android:theme=&quot;@style/Theme.D1&quot; /&gt;
          &lt;activity
              android:name=&quot;.Qiyam&quot;
              android:label=&quot;@string/title_feature6&quot;
              android:theme=&quot;@style/Theme.D1&quot; /&gt;
          &lt;activity
              android:name=&quot;.Ruku&quot;
              android:label=&quot;@string/title_feature7&quot;
              android:theme=&quot;@style/Theme.D1&quot; /&gt;
          &lt;activity
              android:name=&quot;.Sajdah&quot;
              android:label=&quot;@string/title_feature8&quot;
              android:theme=&quot;@style/Theme.D1&quot; /&gt;
          &lt;activity
              android:name=&quot;.SitBetw&quot;
              android:label=&quot;@string/title_feature9&quot;
              android:theme=&quot;@style/Theme.D1&quot; /&gt;
          &lt;activity
              android:name=&quot;.Qunut&quot;
              android:label=&quot;@string/title_feature10&quot;
              android:theme=&quot;@style/Theme.D1&quot; /&gt;
          &lt;activity
              android:name=&quot;.Tahiyyatul&quot;
              android:label=&quot;@string/title_feature11&quot;
              android:theme=&quot;@style/Theme.D1&quot; /&gt;
          &lt;activity
              android:name=&quot;.Salam&quot;
              android:label=&quot;@string/title_feature12&quot;
              android:theme=&quot;@style/Theme.D1&quot; /&gt;
          &lt;activity
              android:name=&quot;.Subuh&quot;
              android:label=&quot;@string/title_feature13&quot;
              android:screenOrientation=&quot;portrait&quot;
              android:theme=&quot;@style/Theme.D1&quot; /&gt;
          &lt;activity
              android:name=&quot;.Dhuhur&quot;
              android:label=&quot;@string/title_feature14&quot;
              android:theme=&quot;@style/Theme.D1&quot; /&gt;
          &lt;activity
              android:name=&quot;.Asr&quot;
              android:label=&quot;@string/title_feature15&quot;
              android:theme=&quot;@style/Theme.D1&quot; /&gt;
          &lt;activity
              android:name=&quot;.Maghrib&quot;
              android:label=&quot;@string/title_feature17&quot;
              android:theme=&quot;@style/Theme.D1&quot; /&gt;
          &lt;activity
              android:name=&quot;.Isha&quot;
              android:label=&quot;@string/title_feature18&quot;
              android:theme=&quot;@style/Theme.D1&quot; /&gt;
          &lt;activity
              android:name=&quot;.Dhuha&quot;
              android:label=&quot;@string/title_feature19&quot;
              android:theme=&quot;@style/Theme.D1&quot; /&gt;
          &lt;activity
              android:name=&quot;.Witir&quot;
              android:label=&quot;@string/title_feature20&quot;
              android:theme=&quot;@style/Theme.D1&quot; /&gt;
          &lt;activity
              android:name=&quot;.Ied&quot;
              android:label=&quot;@string/title_feature21&quot;
              android:theme=&quot;@style/Theme.D1&quot; /&gt;
          &lt;activity
              android:name=&quot;.Tarawih&quot;
              android:label=&quot;@string/title_feature22&quot;
              android:theme=&quot;@style/Theme.D1&quot; /&gt;
          &lt;activity
              android:name=&quot;.Tahajud&quot;
              android:label=&quot;@string/title_feature23&quot;
              android:theme=&quot;@style/Theme.D1&quot; /&gt;
          &lt;activity
              android:name=&quot;.BasicMain&quot;
              android:label=&quot;@string/title_feature23&quot;
              android:theme=&quot;@style/Theme.D1&quot; /&gt;
          &lt;activity
              android:name=&quot;.Fardh&quot;
              android:label=&quot;@string/title_feature23&quot;
              android:theme=&quot;@style/Theme.D1&quot; /&gt;
          &lt;activity
              android:name=&quot;.Sunnah&quot;
              android:label=&quot;@string/title_feature23&quot;
              android:theme=&quot;@style/Theme.D1&quot; /&gt;
          &lt;activity
              android:name=&quot;.Dalil&quot;
              android:label=&quot;@string/title_feature23&quot;
              android:theme=&quot;@style/Theme.D1&quot; /&gt;
          &lt;!--
              &lt;activity android:name=&quot;.AboutActivity&quot;
                    android:theme=&quot;@style/Theme.D1&quot;
                    android:label=&quot;@string/title_about&quot;
                    /&gt;
              &lt;activity android:name=&quot;.SearchActivity&quot;
                    android:theme=&quot;@style/Theme.D1&quot;
                    android:label=&quot;@string/title_search&quot;
                    /&gt;
          --&gt;
          &lt;activity
              android:name=&quot;.SplashActivity&quot;
              android:label=&quot;@string/app_name&quot; &gt;
              &lt;intent-filter&gt;
                  &lt;category android:name=&quot;android.intent.category.LAUNCHER&quot; /&gt;
              &lt;/intent-filter&gt;
          &lt;/activity&gt;
          &lt;activity android:name=&quot;.QuestionActivity&quot; /&gt;
          &lt;activity android:name=&quot;.RulesActivity&quot; /&gt;
          &lt;activity android:name=&quot;.EndgameActivity&quot; /&gt;
          &lt;activity android:name=&quot;.SettingsActivity&quot; /&gt;
          &lt;activity android:name=&quot;.AnswersActivity&quot; /&gt;
      &lt;/application&gt;
      &lt;uses-sdk android:minSdkVersion=&quot;11&quot; /&gt;
      &lt;tool-api-level&gt;
          11
      &lt;/tool-api-level&gt;
  &lt;/manifest&gt;
  </code></pre>
  <p>and this is my LOG:</p>
  <pre><code>07 - 10 11: 38: 01.946: E / AndroidRuntime(7548): FATAL EXCEPTION: main
  07 - 10 11: 38: 01.946: E / AndroidRuntime(7548): java.lang.ClassCastException: android.app.Application cannot be cast to com.wglxy.example.dash1.ChuckApplication
  07 - 10 11: 38: 01.946: E / AndroidRuntime(7548): at com.wglxy.example.dash1.SplashActivity.onClick(SplashActivity.java: 57)
  07 - 10 11: 38: 01.946: E / AndroidRuntime(7548): at android.view.View.performClick(View.java: 4202)
  07 - 10 11: 38: 01.946: E / AndroidRuntime(7548): at android.view.View$PerformClick.run(View.java: 17340)
  07 - 10 11: 38: 01.946: E / AndroidRuntime(7548): at android.os.Handler.handleCallback(Handler.java: 725)
  07 - 10 11: 38: 01.946: E / AndroidRuntime(7548): at android.os.Handler.dispatchMessage(Handler.java: 92)
  07 - 10 11: 38: 01.946: E / AndroidRuntime(7548): at android.os.Looper.loop(Looper.java: 137)
  07 - 10 11: 38: 01.946: E / AndroidRuntime(7548): at android.app.ActivityThread.main(ActivityThread.java: 5039)
  07 - 10 11: 38: 01.946: E / AndroidRuntime(7548): at java.lang.reflect.Method.invokeNative(Native Method)
  07 - 10 11: 38: 01.946: E / AndroidRuntime(7548): at java.lang.reflect.Method.invoke(Method.java: 511)
  07 - 10 11: 38: 01.946: E / AndroidRuntime(7548): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java: 793)
  07 - 10 11: 38: 01.946: E / AndroidRuntime(7548): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java: 560)
  07 - 10 11: 38: 01.946: E / AndroidRuntime(7548): at dalvik.system.NativeStart.main(Native Method)
  </code></pre>
  <p>anyone know how to fix my problem?</p>