title: when i add google analytics, occur classcastException
body: <p>now i'm adding google analytics in my app.</p>
  
  <p>i'm all have done following google analytics homepages.
  (<a href="https://developers.google.com/analytics/devguides/collection/android/v4/#manifest" rel="nofollow">https://developers.google.com/analytics/devguides/collection/android/v4/#manifest</a>)</p>
  
  <p>but after I add Tracker code in my MainActivity, i'm occur ClassCastException when i running my app.</p>
  
  <p>please give me a answer.</p>
  
  <p>i'm already searching google and stack overflow.</p>
  
  <p>behind is my code.</p>
  
  <p>ApplicationTrackers.java</p>
  
  <p><div class="snippet" data-lang="js" data-hide="true">
  <div class="snippet-code snippet-currently-hidden">
  <pre class="snippet-code-js lang-js prettyprint-override"><code>package com.zla.android;
  
  import java.util.HashMap;
  import android.app.Application;
  import com.google.android.gms.analytics.GoogleAnalytics;
  import com.google.android.gms.analytics.Tracker;
  import com.zla.android.R;
  
  public class ApplicationTrackers extends Application {
  
   private static final String PROPERTY_ID = "UA-XXXXXXXX-2";
  
   public enum TrackerName {
    APP_TRACKER, // Tracker used only in this app.
    GLOBAL_TRACKER, // Tracker used by all the apps from a company. eg: roll-up tracking.
    ECOMMERCE_TRACKER, // Tracker used by all ecommerce transactions from a company.
   }
   HashMap&lt;TrackerName, Tracker&gt; mTrackers = new HashMap&lt;TrackerName, Tracker&gt;();
   
   synchronized Tracker getTracker(TrackerName trackerId) {
    if (!mTrackers.containsKey(trackerId)) {   
     GoogleAnalytics analytics = GoogleAnalytics.getInstance(this);
     Tracker t = (trackerId == TrackerName.APP_TRACKER) ? analytics.newTracker(PROPERTY_ID)
       : (trackerId == TrackerName.GLOBAL_TRACKER) ? analytics.newTracker(R.xml.global_tracker)
       : analytics.newTracker(R.xml.ecommerce_tracker);
     mTrackers.put(trackerId, t);     
    }
    return mTrackers.get(trackerId);
   }
  }</code></pre>
  </div>
  </div>
  </p>
  
  <p>global_tracker.xml</p>
  
  <p><div class="snippet" data-lang="js" data-hide="true">
  <div class="snippet-code snippet-currently-hidden">
  <pre class="snippet-code-js lang-js prettyprint-override"><code>&lt;?xml version="1.0" encoding="utf-8"?&gt;
  &lt;resources xmlns:tools="http://schemas.android.com/tools"
  tools:ignore="TypographyDashes"&gt;
   
   &lt;integer name="ga_sessionTimeout"&gt;300&lt;/integer&gt;
  
      &lt;!-- Enable automatic Activity measurement --&gt;
      &lt;bool name="ga_autoActivityTracking"&gt;true&lt;/bool&gt;
  
      &lt;!-- The screen names that will appear in reports --&gt;
      &lt;screenName name="com.zla.android.MainActivity"&gt;
          MainActivity
      &lt;/screenName&gt;
      
      &lt;string name="ga_trackingId"&gt;UA-XXXXXXXX-2&lt;/string&gt;
  &lt;/resources&gt;</code></pre>
  </div>
  </div>
  </p>
  
  <p>ecommerce_tracker.xml</p>
  
  <p><div class="snippet" data-lang="js" data-hide="true">
  <div class="snippet-code snippet-currently-hidden">
  <pre class="snippet-code-js lang-js prettyprint-override"><code>&lt;?xml version="1.0" encoding="utf-8"?&gt;
  &lt;resources&gt;
   &lt;integer name="ga_sessionTimeout"&gt;300&lt;/integer&gt;
   &lt;string name="ga_trackingId"&gt;UA-XXXXXXXX-2&lt;/string&gt;    
  &lt;/resources&gt;</code></pre>
  </div>
  </div>
  </p>
  
  <p>MainActivity.java</p>
  
  <p><div class="snippet" data-lang="js" data-hide="true">
  <div class="snippet-code snippet-currently-hidden">
  <pre class="snippet-code-js lang-js prettyprint-override"><code>package com.zla.android;
  
  import com.google.android.gms.analytics.HitBuilders;
  import com.google.android.gms.analytics.Tracker;
  import android.app.ActionBar;
  import android.app.Activity;
  import android.content.Intent;
  import android.database.Cursor;
  import android.graphics.Color;
  import android.os.Bundle;
  import android.view.Gravity;
  import android.view.View;
  import android.widget.Button;
  import android.widget.ImageView;
  import android.widget.LinearLayout;
  import android.widget.TextView;
  import android.widget.ToggleButton;
  
  public class MainActivity extends Activity {
   
   @Override
   protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    
    
    /* add google analytics --------------------------------------------- */
    Tracker t = ((ApplicationTrackers)getApplication()).getTracker(ApplicationTrackers.TrackerName.APP_TRACKER);
    t.setScreenName("MainActivity");
    t.send(new HitBuilders.AppViewBuilder().build());
    /* ------------------------------------------------------------------ */</code></pre>
  </div>
  </div>
  </p>
  
  <p>androidManifest.xml</p>
  
  <p><div class="snippet" data-lang="js" data-hide="true">
  <div class="snippet-code snippet-currently-hidden">
  <pre class="snippet-code-js lang-js prettyprint-override"><code>&lt;?xml version="1.0" encoding="utf-8"?&gt;
  &lt;manifest xmlns:android="http://schemas.android.com/apk/res/android"
      package="com.zla.android"
      android:versionCode="1"
      android:versionName="1.0" &gt;
  
      &lt;uses-sdk
          android:minSdkVersion="16"
          android:targetSdkVersion="21" /&gt;
      
      &lt;!-- about google analytics --&gt;
   &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="@drawable/app_icon"
          android:label="@string/app_name"
          android:theme="@style/AppTheme"
          android:largeHeap="true"  &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;activity
              android:name="com.zla.android.SearchBrandActivity"
              android:label="search page" /&gt;
          
          &lt;activity
              android:name="com.zla.android.SearchFrameActivity"
              android:label="search page" /&gt;
          
          &lt;activity
              android:name="com.zla.android.ListActivity"
              android:label="list page"
              android:parentActivityName="com.zla.android.MainActivity" &gt;
          &lt;/activity&gt;
          
          &lt;activity
              android:name="com.zla.android.ListActivity_WishList"
              android:label="list page"
              android:parentActivityName="com.zla.android.MainActivity" &gt;
          &lt;/activity&gt;
          
          &lt;activity
              android:name="com.zla.android.DetailActivity"
              android:label="detail page"
              android:parentActivityName="com.zla.android.ListActivity" /&gt;
          
          &lt;!-- about google analytics --&gt;
          &lt;meta-data
     android:name="com.google.android.gms.version"
     android:value="@integer/google_play_services_version" /&gt;
                  
          &lt;activity
              android:name="com.zla.android.ApplicationTrackers"
              android:label="google analytics" /&gt;
          
      &lt;/application&gt;
  
  &lt;/manifest&gt;</code></pre>
  </div>
  </div>
  </p>
  
  <p>error LogCat</p>
  
  <p><div class="snippet" data-lang="js" data-hide="true">
  <div class="snippet-code snippet-currently-hidden">
  <pre class="snippet-code-js lang-js prettyprint-override"><code>04-05 03:27:42.498: E/AndroidRuntime(22322): FATAL EXCEPTION: main
  04-05 03:27:42.498: E/AndroidRuntime(22322): java.lang.RuntimeException: Unable to start activity ComponentInfo{com.zla.android/com.zla.android.MainActivity}: java.lang.ClassCastException: android.app.Application cannot be cast to com.zla.android.ApplicationTrackers
  04-05 03:27:42.498: E/AndroidRuntime(22322):  at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2110)
  04-05 03:27:42.498: E/AndroidRuntime(22322):  at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2135)
  04-05 03:27:42.498: E/AndroidRuntime(22322):  at android.app.ActivityThread.access$700(ActivityThread.java:143)
  04-05 03:27:42.498: E/AndroidRuntime(22322):  at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1241)
  04-05 03:27:42.498: E/AndroidRuntime(22322):  at android.os.Handler.dispatchMessage(Handler.java:99)
  04-05 03:27:42.498: E/AndroidRuntime(22322):  at android.os.Looper.loop(Looper.java:137)
  04-05 03:27:42.498: E/AndroidRuntime(22322):  at android.app.ActivityThread.main(ActivityThread.java:4950)
  04-05 03:27:42.498: E/AndroidRuntime(22322):  at java.lang.reflect.Method.invokeNative(Native Method)
  04-05 03:27:42.498: E/AndroidRuntime(22322):  at java.lang.reflect.Method.invoke(Method.java:511)
  04-05 03:27:42.498: E/AndroidRuntime(22322):  at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:997)
  04-05 03:27:42.498: E/AndroidRuntime(22322):  at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:764)
  04-05 03:27:42.498: E/AndroidRuntime(22322):  at dalvik.system.NativeStart.main(Native Method)
  04-05 03:27:42.498: E/AndroidRuntime(22322): Caused by: java.lang.ClassCastException: android.app.Application cannot be cast to com.zla.android.ApplicationTrackers
  04-05 03:27:42.498: E/AndroidRuntime(22322):  at com.zla.android.MainActivity.onCreate(MainActivity.java:67)
  04-05 03:27:42.498: E/AndroidRuntime(22322):  at android.app.Activity.performCreate(Activity.java:5177)
  04-05 03:27:42.498: E/AndroidRuntime(22322):  at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1094)
  04-05 03:27:42.498: E/AndroidRuntime(22322):  at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2074)
  04-05 03:27:42.498: E/AndroidRuntime(22322):  ... 11 more</code></pre>
  </div>
  </div>
  </p>