Android GCM Retrieve RegistrationID
<p>I am trying to retrieve my GCM registration ID from my android emulator but when i debug the program crashes.
This is my MainActivity code:</p>

<pre><code>  try {
       GCMRegistrar.checkDevice(this);       //  &lt;-- Crashes here
       GCMRegistrar.checkManifest(this);
       final String regId = GCMRegistrar.getRegistrationId(this);
       if (regId.equals("")) 
       {
         GCMRegistrar.register(this,Sender_ID);
       }
       else
       {
         Log.v("Registrationnnnnn", "Already registered");
       }
   }
   catch(Exception e)
   {
       Log.e("ErrorHAi",e.getMessage());
   }
</code></pre>

<p>I've read that this line checks if the device support GCM.But I've installed Google Cloud Messaging from SDK Manager extras. I've also installed </p>

<p>Android SDK Tools : rev 20<br/>
Android SDK Platform Tools : rev 12<br/>
Android 4.1 Api 16</p>

<p>When I mention </p>

<pre><code>&lt;uses-sdk android:minSdkVersion="8" android:targetSdkVersion="16" /&gt;
</code></pre>

<p>this in my manifest file it runs but crashes as I've mentioned in the above code.But if I change the targetSdkVersion to xx as mentioned <a href="http://developer.android.com/guide/google/gcm/gs.html#android-app" rel="nofollow">here</a> it says Install_Failed_OLDER_SDK.</p>

<p>I am currently running this application on  Android 4.1 API level 16.</p>

<p><strong>Update:</strong></p>

<p>My Logcat:</p>

<pre><code>07-03 20:34:25.878: E/Trace(906): error opening trace file: No such file or directory (2)
07-03 22:30:57.748: E/Trace(1016): error opening trace file: No such file or directory (2)
07-03 22:31:01.998: E/AndroidRuntime(1016): FATAL EXCEPTION: main
07-03 22:31:01.998: E/AndroidRuntime(1016): java.lang.RuntimeException: Unable to instantiate receiver com.pack.gcm.MyBroadcastReceiver: java.lang.ClassNotFoundException: com.pack.gcm.MyBroadcastReceiver
07-03 22:31:01.998: E/AndroidRuntime(1016):     at android.app.ActivityThread.handleReceiver(ActivityThread.java:2210)
07-03 22:31:01.998: E/AndroidRuntime(1016):     at android.app.ActivityThread.access$1500(ActivityThread.java:130)
07-03 22:31:01.998: E/AndroidRuntime(1016):     at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1271)
07-03 22:31:01.998: E/AndroidRuntime(1016):     at android.os.Handler.dispatchMessage(Handler.java:99)
07-03 22:31:01.998: E/AndroidRuntime(1016):     at android.os.Looper.loop(Looper.java:137)
07-03 22:31:01.998: E/AndroidRuntime(1016):     at android.app.ActivityThread.main(ActivityThread.java:4745)
07-03 22:31:01.998: E/AndroidRuntime(1016):     at java.lang.reflect.Method.invokeNative(Native Method)
07-03 22:31:01.998: E/AndroidRuntime(1016):     at java.lang.reflect.Method.invoke(Method.java:511)
07-03 22:31:01.998: E/AndroidRuntime(1016):     at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:786)
07-03 22:31:01.998: E/AndroidRuntime(1016):     at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:553)
07-03 22:31:01.998: E/AndroidRuntime(1016):     at dalvik.system.NativeStart.main(Native Method)
07-03 22:31:01.998: E/AndroidRuntime(1016): Caused by: java.lang.ClassNotFoundException: com.pack.gcm.MyBroadcastReceiver
07-03 22:31:01.998: E/AndroidRuntime(1016):     at dalvik.system.BaseDexClassLoader.findClass(BaseDexClassLoader.java:61)
07-03 22:31:01.998: E/AndroidRuntime(1016):     at java.lang.ClassLoader.loadClass(ClassLoader.java:501)
07-03 22:31:01.998: E/AndroidRuntime(1016):     at java.lang.ClassLoader.loadClass(ClassLoader.java:461)
07-03 22:31:01.998: E/AndroidRuntime(1016):     at android.app.ActivityThread.handleReceiver(ActivityThread.java:2205)
07-03 22:31:01.998: E/AndroidRuntime(1016):     ... 10 more
</code></pre>

<p>Now I don't know why it is giving such errors although I've installed all the prerequisites.</p>
