title: android.app.Application cannot be cast to com.example..AnalyticsApplication
body: <p>I am new to android and in a process of adding google analytics to one of my application.
  I am getting the following error when running my application. </p>
  
  <pre><code>android.app.Application cannot be cast to com.xxx.xxx.xxx.AnalyticsApplication
  </code></pre>
  
  <p>This is my main activity.</p>
  
  <pre><code> package com.example.dell.testanalytics;
  
  import android.content.Intent;
  import android.support.v4.app.FragmentPagerAdapter;
  import android.support.v4.view.ViewPager;
  import android.support.v7.app.AppCompatActivity;
  import android.os.Bundle;
  import android.util.Log;
  import android.view.Menu;
  import android.view.MenuItem;
  
  import android.app.Application;
  
  import com.google.android.gms.analytics.GoogleAnalytics;
  import com.google.android.gms.analytics.Logger;
  import com.google.android.gms.analytics.HitBuilders;
  import com.google.android.gms.analytics.Tracker;
  
  
  public class MainActivity extends AppCompatActivity {
      private static final String TAG = "MainActivity";
      private Tracker mTracker;
  
       @Override
      protected void onCreate(Bundle savedInstanceState) {
          super.onCreate(savedInstanceState);
          setContentView(R.layout.activity_main);
  
  
          AnalyticsApplication application = (AnalyticsApplication) getApplication();
          mTracker = application.getDefaultTracker();
  
  
      }
  
      @Override
      public boolean onCreateOptionsMenu(Menu menu) {
  
          getMenuInflater().inflate(R.menu.menu_main, menu);
          return true;
      }
  
      @Override
      public boolean onOptionsItemSelected(MenuItem item) {
  
  // [START screen_view_hit]
          String name = getString(R.string.test);
          Log.i(TAG, "Setting screen name: " + name);
          mTracker.setScreenName("Image~" + name);
          mTracker.send(new HitBuilders.ScreenViewBuilder().build());
          // [END screen_view_hit]
          return false;
      }
  
  
  }
  </code></pre>
  
  <p>The error is pointing the place I call the analytics application method. </p>
  
  <p>This is my manifest file</p>
  
  <pre><code>&lt;?xml version="1.0" encoding="utf-8"?&gt;
  </code></pre>
  
  <p></p>
  
  <pre><code>&lt;uses-permission android:name="android.permission.INTERNET"/&gt;
  &lt;uses-permission android:name="android.permission.ACCESS_NETWORK_STATE"/&gt;
  
  &lt;application
      android:allowBackup="true"
      android:icon="@mipmap/ic_launcher"
      android:label="@string/app_name"
      android:theme="@style/AppTheme" &gt;
      &lt;activity
          android:name=".MainActivity"
          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;/application&gt;
  </code></pre>
  
  <p></p>
  
  <p>I cannot figure out what is wrong since i am not getting any errors or red lines in the code.</p>
  
  <p>Would be great if i could get your assistance. </p>