Note that there are some explanatory texts on larger screens.

plurals
  1. POGoogle GCMIntentService instantiate
    text
    copied!<blockquote> <p><strong>Possible Duplicate:</strong><br> <a href="https://stackoverflow.com/questions/5027147/android-runtimeexception-unable-to-instantiate-the-service">Android RuntimeException: Unable to instantiate the service</a> </p> </blockquote> <p>Trying to get GCM up and running but my device is sending a registration request, but getting no response back from the GCM server. Below I included my manifest and GCMIntentService definition, and my call to register with the GCM server. I've been staring at it so long I might be missing something obvious, if so I apologize.</p> <p>All ideas welcome!</p> <p><strong>Here is my manifest:</strong></p> <pre><code>&lt;manifest xmlns:android="http://schemas.android.com/apk/res/android" package="PACKAGE" android:versionCode="1" android:versionName="1.0" &gt; &lt;uses-sdk android:minSdkVersion="8" android:targetSdkVersion="15" /&gt; &lt;permission android:name="PACKAGE.permission.C2D_MESSAGE" android:protectionLevel="signature" /&gt; &lt;uses-permission android:name="PACKAGE.permission.C2D_MESSAGE" /&gt; &lt;uses-permission android:name="com.google.android.c2dm.permission.RECEIVE" /&gt; &lt;uses-permission android:name="android.permission.WAKE_LOCK" /&gt; &lt;uses-permission android:name="android.permission.INTERNET" /&gt; &lt;application android:icon="@drawable/ic_launcher" android:label="@string/app_name" android:theme="@style/AppTheme" &gt; &lt;service android:name=".GCMIntentService" android:enabled="true"/&gt; &lt;receiver android:name="com.google.android.gcm.GCMBroadcastReceiver" android:permission="com.google.android.c2dm.permission.SEND" &gt; &lt;intent-filter&gt; &lt;action android:name="com.google.android.c2dm.intent.RECEIVE" /&gt; &lt;action android:name="com.google.android.c2dm.intent.REGISTRATION" /&gt; &lt;category android:name="PACKAGE.GCMIntentService" /&gt; &lt;/intent-filter&gt; &lt;/receiver&gt; &lt;activity android:name=".MainActivity" android:label="@string/title_activity_main" &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;/application&gt; &lt;/manifest&gt; </code></pre> <p><strong>Here is my GCMIntentService to handle the return from GCM:</strong></p> <pre><code>import com.google.android.gcm.GCMBaseIntentService; import android.content.Context; import android.content.Intent; import android.util.Log; public class GCMIntentService extends GCMBaseIntentService { public static String TAG = "GCMIntentService"; public GCMIntentService(String senderId) { super(senderId); Log.d("GCMIntentService", senderId); } @Override protected void onError(Context arg0, String arg1) { Log.d("onError", arg1); } @Override protected boolean onRecoverableError(Context context, String errorId){ Log.d("onRecoverableError", errorId); return false; } @Override protected void onMessage(Context arg0, Intent arg1) { Log.d("onMessage", String.valueOf(arg1)); } @Override protected void onRegistered(Context arg0, String arg1) { Log.d("onRegistered", arg1); } @Override protected void onUnregistered(Context arg0, String arg1) { Log.d("onUnregistered", arg1); } } </code></pre> <p><strong>I attempt to register with the following in the onCreate method of my main class:</strong></p> <pre><code>GCMRegistrar.checkDevice(this); GCMRegistrar.checkManifest(this); final String regId = GCMRegistrar.getRegistrationId(this); if (regId.equals("")) { GCMRegistrar.register(this, SENDER_ID); } else { Log.d(TAG, "Already registered"); } </code></pre> <p><strong><em>UPDATE</em></strong> I have tried Raz's suggestion and I got the following error:</p> <pre><code>07-03 12:07:40.459: W/dalvikvm(341): threadid=1: thread exiting with uncaught exception (group=0x4001d800) 07-03 12:07:40.508: E/AndroidRuntime(341): FATAL EXCEPTION: main 07-03 12:07:40.508: E/AndroidRuntime(341): java.lang.RuntimeException: Unable to instantiate service package.gcm2.GCMIntentService: java.lang.InstantiationException: package.gcm2.GCMIntentService 07-03 12:07:40.508: E/AndroidRuntime(341): at android.app.ActivityThread.handleCreateService(ActivityThread.java:2943) 07-03 12:07:40.508: E/AndroidRuntime(341): at android.app.ActivityThread.access$3300(ActivityThread.java:125) 07-03 12:07:40.508: E/AndroidRuntime(341): at android.app.ActivityThread$H.handleMessage(ActivityThread.java:2087) 07-03 12:07:40.508: E/AndroidRuntime(341): at android.os.Handler.dispatchMessage(Handler.java:99) 07-03 12:07:40.508: E/AndroidRuntime(341): at android.os.Looper.loop(Looper.java:123) 07-03 12:07:40.508: E/AndroidRuntime(341): at android.app.ActivityThread.main(ActivityThread.java:4627) 07-03 12:07:40.508: E/AndroidRuntime(341): at java.lang.reflect.Method.invokeNative(Native Method) 07-03 12:07:40.508: E/AndroidRuntime(341): at java.lang.reflect.Method.invoke(Method.java:521) 07-03 12:07:40.508: E/AndroidRuntime(341): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:868) 07-03 12:07:40.508: E/AndroidRuntime(341): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:626) 07-03 12:07:40.508: E/AndroidRuntime(341): at dalvik.system.NativeStart.main(Native Method) 07-03 12:07:40.508: E/AndroidRuntime(341): Caused by: java.lang.InstantiationException: package.gcm2.GCMIntentService 07-03 12:07:40.508: E/AndroidRuntime(341): at java.lang.Class.newInstanceImpl(Native Method) 07-03 12:07:40.508: E/AndroidRuntime(341): at java.lang.Class.newInstance(Class.java:1429) 07-03 12:07:40.508: E/AndroidRuntime(341): at android.app.ActivityThread.handleCreateService(ActivityThread.java:2940) 07-03 12:07:40.508: E/AndroidRuntime(341): ... 10 more 07-03 12:08:34.560: I/Process(341): Sending signal. PID: 341 SIG: 9 </code></pre>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload