title: java.lang.RuntimeException: Unable to instantiate Android stub
body: <p>Sorry if this is a repeated question, it looks basic but I couldn't find any answer.
  I'm trying to run Amazon's SNS KindleMobilePushApp demo app in a Kindle Fire tablet, but I get the following error:</p>
  
  <pre><code>    10-09 14:19:33.508    3101-3101/? W/dalvikvm﹕ threadid=1: thread exiting with uncaught exception (group=0x40b05228)
  10-09 14:19:33.508    3101-3101/? E/AndroidRuntime﹕ FATAL EXCEPTION: main
      java.lang.RuntimeException: Unable to instantiate service com.amazonaws.kindletest.ADMMessageHandler: java.lang.RuntimeException: Stub!
              at android.app.ActivityThread.handleCreateService(ActivityThread.java:2315)
              at android.app.ActivityThread.access$1600(ActivityThread.java:127)
              at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1231)
              at android.os.Handler.dispatchMessage(Handler.java:99)
              at android.os.Looper.loop(Looper.java:137)
              at android.app.ActivityThread.main(ActivityThread.java:4533)
              at java.lang.reflect.Method.invokeNative(Native Method)
              at java.lang.reflect.Method.invoke(Method.java:511)
              at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:784)
              at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:551)
              at dalvik.system.NativeStart.main(Native Method)
       Caused by: java.lang.RuntimeException: Stub!
              at com.amazon.device.messaging.ADMMessageHandlerBase.&lt;init&gt;(Unknown Source)
              at com.amazonaws.kindletest.ADMMessageHandler.&lt;init&gt;(ADMMessageHandler.java:32)
              at java.lang.Class.newInstanceImpl(Native Method)
              at java.lang.Class.newInstance(Class.java:1319)
              at android.app.ActivityThread.handleCreateService(ActivityThread.java:2312)
              at android.app.ActivityThread.access$1600(ActivityThread.java:127)
              at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1231)
              at android.os.Handler.dispatchMessage(Handler.java:99)
              at android.os.Looper.loop(Looper.java:137)
              at android.app.ActivityThread.main(ActivityThread.java:4533)
              at java.lang.reflect.Method.invokeNative(Native Method)
              at java.lang.reflect.Method.invoke(Method.java:511)
              at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:784)
              at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:551)
              at dalvik.system.NativeStart.main(Native Method)
  10-09 14:21:08.359    3101-3101/? E/AndroidRuntime﹕ Handle UnCaght exceptions. KILLING PID: 3101
  </code></pre>
  
  <p>This happens in the default constructor of this class of the sample project:</p>
  
  <pre><code>package com.amazonaws.kindletest;
  
  import java.util.HashMap;
  import java.util.Map;
  import java.util.Set;
  
  import android.app.Notification;
  import android.app.Notification.Builder;
  import android.app.NotificationManager;
  import android.app.PendingIntent;
  import android.content.Context;
  import android.content.Intent;
  import android.os.Bundle;
  import android.util.Log;
  
  import com.amazon.device.messaging.ADMConstants;
  import com.amazon.device.messaging.ADMMessageHandlerBase;
  import com.amazon.device.messaging.ADMMessageReceiver;
  
  public class ADMMessageHandler extends ADMMessageHandlerBase {
      private static String savedMessage = null;
      private static int numberOfMissedMessages = 0;
      public static boolean inBackground = true;
  
      public ADMMessageHandler(){
          super(ADMMessageHandler.class.getName()); //ERROR!
      }
  
      ...
  }
  </code></pre>
  
  <p>Which is derived from this class in Amazon's library:</p>
  
  <pre><code>package com.amazon.device.messaging.ADMMessageHandlerBase
  
  import android.app.IntentService;
  import android.content.Intent;
  
  public abstract class ADMMessageHandlerBase extends IntentService {
      public ADMMessageHandlerBase(String var1) {
          super((String)null);
          throw new RuntimeException("Stub!");
      }
  
      protected final void onHandleIntent(Intent var1) {
          throw new RuntimeException("Stub!");
      }
  
      protected abstract void onMessage(Intent var1);
  
      protected abstract void onRegistrationError(String var1);
  
      protected abstract void onRegistered(String var1);
  
      protected abstract void onUnregistered(String var1);
  }
  </code></pre>
  
  <p>I understand Amazon's class is a stub intended to be replaced by an actual implementation, but how is that done?. This is my build.gradle:</p>
  
  <pre><code>buildscript {
      repositories {
          mavenCentral() // or jcenter()
      }
  
      dependencies {
          classpath 'com.android.tools.build:gradle:1+'
      }
  }
  apply plugin: 'com.android.application'
  android {
      compileSdkVersion 18
      buildToolsVersion "23.0.1"
  
      dependencies {
          compile fileTree(dir: 'libs', include: '*.jar')
      }
  
      defaultConfig {
          applicationId "com.amazonaws.kindletest"
          minSdkVersion 11
          targetSdkVersion 18
      }
  
      buildTypes {
          release {
              minifyEnabled false
              proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.txt'
          }
      }
  }
  </code></pre>
  
  <p>And manifest:</p>
  
  <pre><code>&lt;manifest xmlns:android="http://schemas.android.com/apk/res/android"
      xmlns:amazon="http://schemas.amazon.com/apk/res/android"
      package="com.amazonaws.kindletest"
      android:versionCode="1"
      android:versionName="1.0" &gt;
  
      &lt;uses-sdk
          android:minSdkVersion="11"
          android:targetSdkVersion="18" /&gt;
  
     &lt;!-- This permission ensures that no other application can intercept your ADM messages. It
     should have the form packagename.permission.RECIEVE_ADM_MESSAGE where packagename is the
     name defined in the "package" property of the manifest tag. --&gt; 
      &lt;permission android:name="com.amazonaws.kindletest.permission.RECEIVE_ADM_MESSAGE"
          android:protectionLevel="signature"/&gt;
  
      &lt;!-- Required permissions --&gt;
      &lt;uses-permission android:name="com.amazonaws.kindletest.permission.RECEIVE_ADM_MESSAGE"/&gt;
      &lt;uses-permission android:name="com.amazon.device.messaging.permission.RECEIVE"/&gt;
      &lt;uses-permission android:name="android.permission.INTERNET"/&gt;
      &lt;uses-permission android:name="android.permission.WAKE_LOCK"/&gt;
  
      &lt;application
          android:icon="@drawable/ic_launcher"
          android:label="@string/app_name"        
          android:theme="@style/AppTheme" &gt;
          &lt;activity
              android:name="com.amazonaws.kindletest.KindleMobilePushApp"
              android:screenOrientation="portrait"
              android:label="@string/title_activity_main"
              android:launchMode="singleTop" &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;!-- Your application's API Key --&gt;
          &lt;meta-data android:name="AmazonAPIKey" android:value="@string/api_key"/&gt;
  
          &lt;!--  Declare your ADMMessageHandlerBase implementation as a service --&gt;
          &lt;service android:name="com.amazonaws.kindletest.ADMMessageHandler" 
              android:exported="false" /&gt;
  
          &lt;!-- You must explicitly enable ADM. You must also declare whether your application will run with or without ADM.
          If you specify android:required="false", your app must degrade gracefully when ADM is unavailable. --&gt;
          &lt;amazon:enable-feature android:name="com.amazon.device.messaging" 
              android:required="true" /&gt;
  
          &lt;receiver android:name="com.amazonaws.kindletest.ADMMessageHandler$MessageAlertReceiver" 
              android:permission="com.amazon.device.messaging.permission.SEND"&gt;
              &lt;intent-filter&gt;
                 &lt;action android:name="com.amazon.device.messaging.intent.REGISTRATION" /&gt; 
                 &lt;action android:name="com.amazon.device.messaging.intent.RECEIVE" /&gt; 
                 &lt;category android:name="com.amazonaws.kindletest"/&gt;
              &lt;/intent-filter&gt;
          &lt;/receiver&gt;
  
      &lt;/application&gt;
  
  &lt;/manifest&gt;
  </code></pre>
  
  <p>I have posted <a href="https://forums.aws.amazon.com/thread.jspa?messageID=677591&amp;#677591" rel="nofollow">posted about this</a> in Amazon's developer forum with no success yet. Please let me know if you need more information, thank you.</p>