title: Exception MultiDexApplication Cannot be Cast to Class from getApplication()
body: <p>I have followed the answer here, yet it is not changing anything:</p>
  
  <p><a href="https://stackoverflow.com/questions/35658796/exception-android-support-multidex-multidexapplication-cannot-be-cast-class">exception android.support.multidex.MultiDexApplication cannot be cast class</a></p>
  
  <p>I have a MyApplication class that extends MultiDexApplication. In my main activity I am calling getApplication() and casting it to (MyApplication). My manifest has the name of the application set to .MyApplication. This is in Android Studio. Any help would be appreciated. Thanks!</p>
  
  <p>Error:                                                                               </p>
  
  <pre><code>FATAL EXCEPTION: main
                                                                                     Process: com.gametest.gametest123, PID: 4804
                                                                                     java.lang.RuntimeException: Unable to start activity ComponentInfo{com.gametest.gametest123/com.gametest.gametest123.GamesActivity}: java.lang.ClassCastException: android.support.multidex.MultiDexApplication cannot be cast to com.gametest.gametest123.MyApplication
                                                                                         at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2205)
                                                                                         at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2255)
                                                                                         at android.app.ActivityThread.access$800(ActivityThread.java:142)
                                                                                         at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1203)
                                                                                         at android.os.Handler.dispatchMessage(Handler.java:102)
                                                                                         at android.os.Looper.loop(Looper.java:136)
                                                                                         at android.app.ActivityThread.main(ActivityThread.java:5118)
                                                                                         at java.lang.reflect.Method.invokeNative(Native Method)
                                                                                         at java.lang.reflect.Method.invoke(Method.java:515)
                                                                                         at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:790)
                                                                                         at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:606)
                                                                                         at dalvik.system.NativeStart.main(Native Method)
                                                                                      Caused by: java.lang.ClassCastException: android.support.multidex.MultiDexApplication cannot be cast to com.gametest.gametest123.MyApplication
                                                                                         at com.gametest.gametest123.GamesActivity.onCreate(GamesActivity.java:124)
                                                                                         at android.app.Activity.performCreate(Activity.java:5275)
                                                                                         at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1087)
                                                                                         at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2169)
                                                                                         at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2255) 
                                                                                         at android.app.ActivityThread.access$800(ActivityThread.java:142) 
                                                                                         at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1203) 
                                                                                         at android.os.Handler.dispatchMessage(Handler.java:102) 
                                                                                         at android.os.Looper.loop(Looper.java:136) 
                                                                                         at android.app.ActivityThread.main(ActivityThread.java:5118) 
                                                                                         at java.lang.reflect.Method.invokeNative(Native Method) 
                                                                                         at java.lang.reflect.Method.invoke(Method.java:515) 
                                                                                         at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:790) 
                                                                                         at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:606) 
                                                                                         at dalvik.system.NativeStart.main(Native Method) 
  </code></pre>
  
  <p>Manifest:</p>
  
  <pre><code>&lt;?xml version="1.0" encoding="utf-8"?&gt;
  &lt;manifest xmlns:android="http://schemas.android.com/apk/res/android" xmlns:tools="http://schemas.android.com/tools"
      package="com.gametest.gametest123"
      android:versionCode="33"
      android:versionName="3.0.7" &gt;
  
      &lt;uses-sdk android:minSdkVersion="15" android:targetSdkVersion="26" /&gt;
  
      &lt;!-- Only this application can receive the messages and registration result --&gt;
      &lt;permission android:name="com.gametest.gametest123.permission.C2D_MESSAGE" android:protectionLevel="signature" /&gt;
      &lt;uses-permission android:name="com.gametest.gametest123.permission.C2D_MESSAGE" /&gt;
  
      &lt;!-- This app has permission to register and receive message --&gt;
      &lt;uses-permission android:name="com.google.android.c2dm.permission.RECEIVE" /&gt;
  
      &lt;!-- Send the registration id to the server --&gt;
      &lt;uses-permission android:name="android.permission.INTERNET" /&gt;
  
      &lt;!-- Generic permissions --&gt;
      &lt;uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" /&gt;
      &lt;uses-permission android:name="android.permission.WAKE_LOCK"/&gt;
      &lt;uses-permission android:name="android.permission.VIBRATE"/&gt;
      &lt;uses-permission android:name="android.permission.READ_PHONE_STATE" /&gt;
      &lt;uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" /&gt;
  
      &lt;!-- calldorado Permissions--&gt;
      &lt;uses-feature android:name="android.hardware.telephony" android:required="false"/&gt;
      &lt;uses-permission android:name="android.permission.ACCESS_COARSE_LOCATION" /&gt;
      &lt;uses-permission android:name="android.permission.ACCESS_FINE_LOCATION" 
          android:maxSdkVersion="22" &gt;&lt;!--Calldorado XML analyzer inserted the attribute android:maxSdkVersion="22" in order to make the code compatible with the Google Play store--&gt;
      &lt;/uses-permission&gt;
      &lt;uses-permission android:name="android.permission.ACCESS_WIFI_STATE" 
          android:maxSdkVersion="22" &gt;&lt;!--Calldorado XML analyzer inserted the attribute android:maxSdkVersion="22" in order to make the code compatible with the Google Play store--&gt;
      &lt;/uses-permission&gt;
      &lt;uses-permission android:name="android.permission.PROCESS_OUTGOING_CALLS" /&gt;
      &lt;uses-permission android:name="android.permission.CALL_PHONE" /&gt;
      &lt;uses-permission android:name="android.permission.RECEIVE_BOOT_COMPLETED" /&gt;
      &lt;uses-permission android:name="android.permission.READ_CONTACTS" /&gt;
      &lt;uses-permission android:name="android.permission.READ_CALL_LOG" /&gt;
      &lt;uses-permission android:name="android.permission.WRITE_CONTACTS" /&gt;
      &lt;uses-permission android:name="android.permission.SYSTEM_ALERT_WINDOW" /&gt;
  
      &lt;supports-screens
          android:smallScreens="true"
          android:normalScreens="true"
          android:largeScreens="true"
          /&gt;
  
      &lt;application
          android:icon="@drawable/icon"
          android:label="@string/SHORT_APP_NAME"
          android:name=".MyApplication"
          tools:replace="android:label"&gt;
  
  
  
          &lt;receiver
                  android:name="com.google.android.gcm.GCMBroadcastReceiver"
                  android:permission="com.google.android.c2dm.permission.SEND" &gt;
              &lt;intent-filter&gt;
                  &lt;action android:name="com.google.android.c2dm.intent.RECEIVE" /&gt;
                  &lt;action android:name="com.google.android.c2dm.intent.REGISTRATION" /&gt;
  
                  &lt;category android:name="com.gametest.gametest123" /&gt;
              &lt;/intent-filter&gt;
          &lt;/receiver&gt;
  
          &lt;receiver android:name="com.gametest.gametest123.LocalNotification"&gt;&lt;/receiver&gt;
  
          &lt;receiver android:name="com.gametest.gametest123.CloseApp"&gt;&lt;/receiver&gt;
  
          &lt;service android:name="com.gametest.gametest123.GCMIntentService" /&gt;
  
          &lt;activity
              android:name="com.gametest.gametest123.activities.ViewApp"
              android:label="@string/SHORT_APP_NAME"
              android:theme="@android:style/Theme.NoTitleBar"
              android:screenOrientation="portrait"
              /&gt;
  
          &lt;activity
                  android:name="com.gametest.gametest123.LoadViewApp"
                  android:label="@string/SHORT_APP_NAME"
                  android:theme="@android:style/Theme.NoTitleBar"
                  android:screenOrientation="portrait"
                  /&gt;
  
          &lt;activity
                  android:name="com.gametest.gametest123.activities.OfferPage"
                  android:label="@string/SHORT_APP_NAME"
                  android:theme="@android:style/Theme.NoTitleBar"
                  android:screenOrientation="portrait"
                  /&gt;
  
          &lt;activity
              android:name="com.gametest.gametest123.discover.DiscoverApps"
              android:label="@string/TITLESTRING_WHATSNEW"
              android:screenOrientation="portrait"
              /&gt;
  
          &lt;activity
              android:name="com.gametest.gametest123.activities.ChooseMailClient"
              android:theme="@android:style/Theme.NoTitleBar"
              android:screenOrientation="portrait"
              /&gt;
  
          &lt;activity
                  android:name="com.tapjoy.TJAdUnitActivity"
                  android:configChanges="orientation|keyboardHidden|screenSize"
                  android:hardwareAccelerated="true"
                  android:theme="@android:style/Theme.Translucent.NoTitleBar.Fullscreen" /&gt;
          &lt;activity
                  android:name="com.tapjoy.mraid.view.ActionHandler"
                  android:configChanges="orientation|keyboardHidden|screenSize" /&gt;
          &lt;activity
                  android:name="com.tapjoy.mraid.view.Browser"
                  android:configChanges="orientation|keyboardHidden|screenSize" /&gt;
          &lt;activity
                  android:name="com.tapjoy.TJContentActivity"
                  android:configChanges="orientation|keyboardHidden|screenSize"
                  android:theme="@android:style/Theme.Translucent.NoTitleBar" /&gt;
  
          &lt;meta-data android:name="com.google.android.gms.games.APP_ID"
                     android:value="@string/app_id" /&gt;
  
          &lt;activity android:name="com.facebook.FacebookActivity"
                    android:configChanges=
                            "keyboard|keyboardHidden|screenLayout|screenSize|orientation"
                    android:theme="@android:style/Theme.Translucent.NoTitleBar"
                    android:label="@string/SHORT_APP_NAME"
                    tools:replace="android:theme"/&gt;
  
          &lt;!-- TODO: Fix --&gt;
                    &lt;!--android:label="@string/app_name" /--&gt;
  
          &lt;activity android:name="com.fyber.ads.ofw.OfferWallActivity"
                    android:configChanges="orientation|screenSize" /&gt;
  
  
          &lt;!-- The GAMES activity --&gt;
          &lt;activity
              android:name="com.gametest.gametest123.GamesActivity"
              android:label="@string/SHORT_APP_NAME"
              android:theme="@android:style/Theme.NoTitleBar"
              android:screenOrientation="portrait"&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;meta-data android:name="com.facebook.sdk.ApplicationId" android:value="@string/facebook_app_id"/&gt;
  
          &lt;provider
                  android:authorities="com.facebook.app.FacebookContentProvider1730237540533882"
                  android:name="com.facebook.FacebookContentProvider"
                  android:exported="true"/&gt;
  
          &lt;!-- Optionally, register AnalyticsReceiver and AnalyticsService to support background
       dispatching on non-Google Play devices --&gt;
          &lt;receiver android:name="com.google.android.gms.analytics.AnalyticsReceiver"
                    android:enabled="true"&gt;
              &lt;intent-filter&gt;
                  &lt;action android:name="com.google.android.gms.analytics.ANALYTICS_DISPATCH" /&gt;
              &lt;/intent-filter&gt;
          &lt;/receiver&gt;
          &lt;service android:name="com.google.android.gms.analytics.AnalyticsService"
                   android:enabled="true"
                   android:exported="false"/&gt;
  
          &lt;!-- Optionally, register CampaignTrackingReceiver and CampaignTrackingService to enable
               installation campaign reporting --&gt;
          &lt;receiver android:name="com.google.android.gms.analytics.CampaignTrackingReceiver"
                    android:exported="true"&gt;
              &lt;intent-filter&gt;
                  &lt;action android:name="com.android.vending.INSTALL_REFERRER" /&gt;
              &lt;/intent-filter&gt;
          &lt;/receiver&gt;
          &lt;service android:name="com.google.android.gms.analytics.CampaignTrackingService" /&gt;
      &lt;/application&gt;
  
  &lt;/manifest&gt;
  </code></pre>
  
  <p>MyApplication:</p>
  
  <pre><code>package com.gametest.gametest123;
  
  import android.app.Activity;
  import android.app.Application;
  import android.content.Context;
  import android.support.multidex.MultiDex;
  import android.support.multidex.MultiDexApplication;
  
  import com.google.android.gms.analytics.GoogleAnalytics;
  import com.google.android.gms.analytics.Tracker;
  
  public class MyApplication extends MultiDexApplication {
      private Tracker mTracker;
  
      private Activity mCurrentActivity = null;
  
      public void setCurrentActivity(Activity mCurrectActivity) {
          this.mCurrentActivity = mCurrectActivity;
      }
  
      public Activity getCurrentActivity() {
          return mCurrentActivity;
      }
  
      private static Context mAppContext;
  
      private static MyApplication mInstance;
  
      @Override
      public void onCreate() {
          super.onCreate();
          MultiDex.install(this);
          mInstance = this;
          this.setAppContext(getApplicationContext());
      }
  
      protected void attachBaseContext(Context base) {
          super.attachBaseContext(base);
          MultiDex.install(this);
      }
  
      public static MyApplication getInstance() {
          return mInstance;
      }
  
      public static Context getAppContext() {
          return mAppContext;
      }
  
      public void setAppContext(Context mAppContext) {
          this.mAppContext = mAppContext;
      }
  
      /**
       * Gets the default {@link Tracker} for this {@link Application}.
       * @return tracker
       */
      synchronized public Tracker getDefaultTracker() {
          if (mTracker == null) {
              GoogleAnalytics analytics = GoogleAnalytics.getInstance(this);
              // To enable debug logging use: adb shell setprop log.tag.GAv4 DEBUG
              mTracker = analytics.newTracker(R.string.ga_trackingId);
          }
          return mTracker;
      }
  }
  </code></pre>
  
  <p>GamesActivity up to the line where it crashes:</p>
  
  <pre><code>public class GamesActivity extends AndroidApplication implements DownloadAndParseJsonAppTask.DownloadAndParseJsonInterface, DialogInterface.OnCancelListener, PlayGames {
  
      private int mPresentNumber = 0;
  
      public ActionResolverAndroid actionResolverAndroid;
      public PlayGames mPlayGames;
  
      private boolean userIsWaitingForConnection = false;
  
      // Array to store all button elements initialized with 25 false elements (boolean is false by default, Boolean is null)
      private boolean[] mDoorsArray = new boolean[25];
  
      private DownloadAndParseJsonAppTask mTask;
      private Chartboost chartboost;
  
      // Loading data properties
      public ProgressDialog mLoadingDialog = null;
      public ArrayList&lt;JsonData&gt; mArrayJsonData;
      public String mLastModified = null;
  
      public Intent ofwIntent;
      public static final int REQUEST_CODE = 102;
  
      // Client used to interact with Google APIs
  //    private GoogleApiClient mGoogleApiClient;
      GameHelper gameHelper;
  
      public boolean loadUrl = true;
  
      @Override
      public void onCreate(Bundle savedInstanceState) {
          super.onCreate(savedInstanceState);
          getADID();
  
  
          AndroidPermissions.check(this)
                  .permissions(Manifest.permission.READ_PHONE_STATE)
                  .hasPermissions(new Checker.Action0() {
                      @Override
                      public void call(String[] permissions) {
                          // do something..
                      }
                  })
                  .noPermissions(new Checker.Action1() {
                      @Override
                      public void call(String[] permissions) {
                          // do something..
                          ActivityCompat.requestPermissions(GamesActivity.this
                                  , new String[]{Manifest.permission.READ_PHONE_STATE}
                                  , REQUEST_CODE);
                      }
                  })
                  .check();
  
          // Load Google Analytics
  
          //THIS IS WHERE THE APP CRASHES
          ((MyApplication) getApplication()).getDefaultTracker();
  </code></pre>