title: GoogleCloudMessaging InstanceID.getInstance returns null
body: <p>I've been looking around for the problem I'm facing but have yet to find anything pertaining to what I'm getting from trying to get the InstanceID from GoogleCloudMessaging. I've tried setting up the call in a class extending IntentService and also tried using AsyncTask to call it in the background, but to no avail. </p>
  
  <p>I've been following tutorials on how to set up the Manifest and the application in order to obtain the right information. Anyone have any clue what could be wrong? My logs say that there is a nullPointerException at InstanceID.getInstance(getApplicationContext());</p>
  
  <p>my call:</p>
  
  <pre><code>private class RegisterGCM extends IntentService{
      public RegisterGCM(){
          super("GcmIntentService");
          registerDevice();
      }
      private void registerDevice(){
          InstanceID instanceId = InstanceID.getInstance(getApplicationContext());
  
          //Constants contains GCM_SENDER_ID which is the project number from Google Developer Console
          String token = instanceId.getToken(Constants.GCM_SENDER_ID, GoogleCloudMessaging.INSTANCE_ID_SCOPE);
      }
  }
  </code></pre>
  
  <p>I put this class in my LandingPage class after logging in and call it by:</p>
  
  <pre><code>new RegisterGCM();
  </code></pre>
  
  <p>This is called right after checking if the play services are up to date and updated. </p>
  
  <p>Any ideas? If I need to provide more information I can, but this is just a snippet of what I can post.</p>
  
  <p>EDIT:
  Tried adding intent-filter to service in the Manifest and checking if getApplicationContext() is null and this is what the exception coming back tells me:</p>
  
  <pre><code>06-15 16:42:38.614: W/System.err(17295): java.lang.NullPointerException:   Attempt to invoke virtual method 'android.content.Context android.content.Context.getApplicationContext()' on a null object reference
  06-15 16:42:38.624: W/System.err(17295):    at android.content.ContextWrapper.getApplicationContext(ContextWrapper.java:110)
  06-15 16:42:38.624: W/System.err(17295):    at com.google.android.gms.iid.InstanceID.zza(Unknown Source)
  06-15 16:42:38.624: W/System.err(17295):    at com.google.android.gms.iid.InstanceID.getInstance(Unknown Source)
  06-15 16:42:38.624: W/System.err(17295):    at .gcmnotification.GcmIntentService.registerDevice(GcmIntentService.java:33)
  06-15 16:42:38.624: W/System.err(17295):    at .gcmnotification.GcmIntentService.&lt;init&gt;(GcmIntentService.java:29)
  06-15 16:42:38.624: W/System.err(17295):    at .LandingPageActivity.onCreate(LandingPageActivity.java:115)
  06-15 16:42:38.624: W/System.err(17295):    at android.app.Activity.performCreate(Activity.java:6289)
  06-15 16:42:38.624: W/System.err(17295):    at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1119)
  06-15 16:42:38.624: W/System.err(17295):    at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2665)
  06-15 16:42:38.624: W/System.err(17295):    at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2777)
  06-15 16:42:38.624: W/System.err(17295):    at android.app.ActivityThread.access$900(ActivityThread.java:179)
  06-15 16:42:38.624: W/System.err(17295):    at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1462)
  06-15 16:42:38.624: W/System.err(17295):    at android.os.Handler.dispatchMessage(Handler.java:102)
  06-15 16:42:38.624: W/System.err(17295):    at android.os.Looper.loop(Looper.java:145)
  06-15 16:42:38.624: W/System.err(17295):    at android.app.ActivityThread.main(ActivityThread.java:5972)
  06-15 16:42:38.624: W/System.err(17295):    at java.lang.reflect.Method.invoke(Native Method)
  06-15 16:42:38.624: W/System.err(17295):    at java.lang.reflect.Method.invoke(Method.java:372)
  06-15 16:42:38.624: W/System.err(17295):    at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:1388)
  06-15 16:42:38.624: W/System.err(17295):    at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:1183)
  </code></pre>
  
  <p>this is the error message returned from my catch block:
  Attempt to invoke virtual method 'android.content.Context android.content.Context.getApplicationContext()' on a null object reference</p>
  
  <p>So I'm guessing the getApplicationContext is returning null?</p>