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.
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());
my call:
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);
}
}
I put this class in my LandingPage class after logging in and call it by:
new RegisterGCM();
This is called right after checking if the play services are up to date and updated.
Any ideas? If I need to provide more information I can, but this is just a snippet of what I can post.
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:
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.<init>(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)
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
So I'm guessing the getApplicationContext is returning null?