title: Google Tag Manager for Android NullPointerException
body: <p>I'm trying to setup a Universal Analytics tag via Google Tag Manager for Android. I have a blank activity (nothing in the layout) as follows:</p>
  
  <pre><code>@Override
  protected void onCreate(Bundle savedInstanceState)
  {
      super.onCreate(savedInstanceState);
      setContentView(R.layout.activity_verification);
  
      // Start GTM code
  
      try
      {
          TagManager tagManager = TagManager.getInstance(this);
          tagManager.setVerboseLoggingEnabled(true);
          PendingResult&lt;ContainerHolder&gt; pending = tagManager.loadContainerPreferNonDefault("GTM-XXXXXX", R.raw.default_gtm_container);
          pending.setResultCallback(new ResultCallback&lt;ContainerHolder&gt;()
          {
              @Override
              public void onResult(ContainerHolder containerHolder)
              {
                  ContainerHolderSingleton.setContainerHolder(containerHolder);
                  if (!containerHolder.getStatus().isSuccess())
                  {
                      Log.e("GoogleTagManager", "failure loading container");
                      return;
                  }
                  ContainerHolderSingleton.setContainerHolder(containerHolder);
                  containerHolder.setContainerAvailableListener(new ContainerHolder.ContainerAvailableListener()
                  {
  
                      @Override
                      public void onContainerAvailable(ContainerHolder containerHolder, String containerVersion)
                      {
                          containerHolder.getContainer();
                      }
                  });
              }
          }, 2, TimeUnit.SECONDS);
      } catch (Exception e)
      {
          e.printStackTrace();
      }
  
      // End GTM code
  }
  
  @Override
  public void onStart()
  {
      super.onStart();
      DataLayer dataLayer = TagManager.getInstance(this).getDataLayer();
      dataLayer.pushEvent("openScreen", DataLayer.mapOf("screenName", "Verification"));
  }
  </code></pre>
  
  <p>All I'm trying to do is have the Universal Analytics tag fire when this activity starts. As you can see from the log output:</p>
  
  <pre><code>04-23 06:49:56.745: D/dalvikvm(4334): Not late-enabling CheckJNI (already on)
  04-23 06:49:56.855: V/GoogleTagManager(4334): Atttempting to load container from resource ID 2131034112
  04-23 06:49:56.855: W/GoogleTagManager(4334): Resource is a UTF-8 encoded string but doesn't contain a JSON container
  04-23 06:49:56.865: V/GoogleTagManager(4334): Deleted 0 expired items
  04-23 06:49:56.875: V/GoogleTagManager(4334): Start loading resource from disk ...
  04-23 06:49:56.875: W/dalvikvm(4334): threadid=13: thread exiting with uncaught exception (group=0xb2d4fb20)
  04-23 06:49:56.885: W/GoogleTagManager(4334): GooglePlayServicesNotAvailableException getting Advertising Id Info
  04-23 06:49:56.885: E/AndroidRuntime(4334): FATAL EXCEPTION: pool-2-thread-1
  04-23 06:49:56.885: E/AndroidRuntime(4334): Process: com.outing.planner, PID: 4334
  04-23 06:49:56.885: E/AndroidRuntime(4334): java.lang.NullPointerException
  04-23 06:49:56.885: E/AndroidRuntime(4334):     at com.google.android.gms.tagmanager.o$b.a(Unknown Source)
  04-23 06:49:56.885: E/AndroidRuntime(4334):     at com.google.android.gms.tagmanager.o$b.i(Unknown Source)
  04-23 06:49:56.885: E/AndroidRuntime(4334):     at com.google.android.gms.tagmanager.cq.jC(Unknown Source)
  04-23 06:49:56.885: E/AndroidRuntime(4334):     at com.google.android.gms.tagmanager.cq$1.run(Unknown Source)
  04-23 06:49:56.885: E/AndroidRuntime(4334):     at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1112)
  04-23 06:49:56.885: E/AndroidRuntime(4334):     at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:587)
  04-23 06:49:56.885: E/AndroidRuntime(4334):     at java.lang.Thread.run(Thread.java:841)
  04-23 06:49:56.915: D/dalvikvm(4334): GC_FOR_ALLOC freed 239K, 9% free 2999K/3292K, paused 17ms, total 17ms
  04-23 06:49:57.225: D/(4334): HostConnection::get() New Host Connection established 0xb8c8e590, tid 4334
  04-23 06:49:57.245: W/EGL_emulation(4334): eglSurfaceAttrib not implemented
  04-23 06:49:57.245: D/OpenGLRenderer(4334): Enabling debug mode 0
  04-23 06:50:01.945: V/GoogleTagManager(4334): connecting to Analytics service
  04-23 06:50:01.945: V/GoogleTagManager(4334): connect: bindService returned false for Intent { act=com.google.android.gms.analytics.service.START cmp=com.google.android.gms/.analytics.service.AnalyticsService (has extras) }
  04-23 06:50:01.945: W/GoogleTagManager(4334): Service unavailable (code=1), will retry.
  04-23 06:50:01.945: V/GoogleTagManager(4334): Loaded clientId
  04-23 06:50:01.945: I/GoogleTagManager(4334): No campaign data found.
  04-23 06:50:01.945: V/GoogleTagManager(4334): Initialized GA Thread
  04-23 06:50:01.945: W/GoogleTagManager(4334): GooglePlayServicesNotAvailableException getting Ad Id Info
  04-23 06:50:01.945: V/GoogleTagManager(4334): putHit called
  04-23 06:50:06.965: V/GoogleTagManager(4334): connecting to Analytics service
  04-23 06:50:06.965: V/GoogleTagManager(4334): connect: bindService returned false for Intent { act=com.google.android.gms.analytics.service.START cmp=com.google.android.gms/.analytics.service.AnalyticsService (has extras) }
  04-23 06:50:06.965: W/GoogleTagManager(4334): Service unavailable (code=1), using local store.
  04-23 06:50:06.965: V/GoogleTagManager(4334): falling back to local store
  04-23 06:50:06.965: V/GoogleTagManager(4334): Sending hit to store  PATH: https:  PARAMS: v=1,  ul=en-us,  t=appview,  ht=1398250196938,  sr=480x800,  an=OutingPlannerAndroid,  tid=UA-XXXXXXXX-Y,  aid=com.outing.planner,  cid=c5f3e490-a578-49d6-b0e7-eaf3bce8dfe6,  av=1.0,  _u=.4nL,  cd=Verification,  
  04-23 06:50:06.965: V/GoogleTagManager(4334): PowerSaveMode initiated.
  04-23 06:50:06.975: V/GoogleTagManager(4334): PowerSaveMode terminated.
  04-23 06:50:06.975: V/GoogleTagManager(4334): Dispatch running...
  04-23 06:50:07.405: D/dalvikvm(4334): GC_FOR_ALLOC freed 336K, 11% free 3177K/3568K, paused 6ms, total 6ms
  04-23 06:50:08.215: V/GoogleTagManager(4334): sent 1 of 1 hits
  04-23 06:50:08.225: V/GoogleTagManager(4334): PowerSaveMode initiated.
  </code></pre>
  
  <p>although a <code>NullPointerException</code> is thrown, the Google Analytics hit is actually sent and I see the hit in the realtime reports. The <code>NullPointerException</code> is causing my application to crash and the Google Analytics hit is sent even after the application crashes.</p>
  
  <p>Why is the <code>NullPointerException</code> being thrown? It seems to be thrown by the Google Tag Manager classes, but I don't know what I'm doing wrong. I followed the CuteAnimalV4 sample project down to the last letter.</p>
  
  <p>Please note I've hidden the Google Tag Manager container ID and the Google Analytics account ID. These are valid values in real life.</p>