title: Runtime error starting Service caused by ClassCastException
body: <p>I am getting runtime error, trying to start a boot-time service.  Its failing but there is no hint I can see.  The intent is finding the Service but it doesn't get to onCreate or onStart.</p>
  
  <pre><code>public class ControlReceiver extends BroadcastReceiver
  {
    /**
     * @see android.content.BroadcastReceiver#onReceive(Context,Intent)
     */
    @Override
    public void onReceive(Context context, Intent intent)
    {
      Intent service = new Intent(context, MyApp.class);
      Log.d("rcvr", "Received intent:" + intent.getAction());
      context.startService(service);
    }
  }
  </code></pre>
  
  <p>The manifest:</p>
  
  <pre><code>&lt;manifest 
      android:versionCode="1" 
      android:versionName="1.0"
      package="com.company.package" 
      xmlns:android="http://schemas.android.com/apk/res/android"&gt;
      &lt;uses-sdk 
          android:minSdkVersion="9" 
          android:targetSdkVersion="10"/&gt;
      &lt;uses-permission android:name="android.permission.ACCESS_FINE_LOCATION"/&gt;
      &lt;uses-permission android:name="android.permission.ACCESS_GPS"/&gt;
      &lt;uses-permission android:name="android.permission.ACCESS_MOCK_LOCATION"/&gt;
      &lt;uses-permission android:name="android.permission.ACCESS_COARSE_LOCATION"/&gt;
      &lt;uses-permission android:name="android.permission.INTERNET"/&gt;
      &lt;uses-permission android:name="android.permission.ACCESS_NETWORK_STATE"/&gt;
      &lt;uses-permission android:name="android.permission.ACCESS_LOCATION"/&gt;
      &lt;uses-permission android:name="android.permission.ACCESS_ASSISTED_GPS"/&gt;
      &lt;uses-permission android:name="android.permission.ACCESS_CELL_ID"/&gt;
      &lt;uses-permission android:name="android.permission.READ_PHONE_STATE"/&gt;
      &lt;uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE"/&gt;
      &lt;uses-permission android:name="android.permission.READ_LOGS"/&gt;
      &lt;uses-permission android:name="android.permission.SET_ACTIVITY_WATCHER"/&gt;
      &lt;uses-permission android:name="android.permission.STATUS_BAR"/&gt;
      &lt;uses-permission android:name="android.permission.RECEIVE_BOOT_COMPLETED"/&gt;
      &lt;uses-permission android:name="android.permission.BROADCAST_STICKY"/&gt;
      &lt;uses-permission android:name="android.permission.CONTROL_LOCATION_UPDATES"/&gt;
      &lt;uses-permission android:name="android.permission.SET_DEBUG_APP"/&gt;
      &lt;uses-permission android:name="android.permission.BATTERY_STATS"/&gt;
      &lt;uses-permission android:name="android.permission.ACCESS_LOCATION_EXTRA_COMMANDS"/&gt;
      &lt;uses-permission android:name="android.permission.BIND_DEVICE_ADMIN"/&gt;
      &lt;uses-permission android:name="android.permission.DIAGNOSTIC"/&gt;
      &lt;uses-permission android:name="android.permission.DEVICE_POWER"/&gt;
      &lt;uses-permission android:name="android.permission.DUMP"/&gt;
      &lt;uses-permission android:name="android.permission.CHANGE_COMPONENT_ENABLED_STATE"/&gt;
      &lt;uses-permission android:name="android.permission.SIGNAL_PERSISTENT_PROCESSES"/&gt;
      &lt;uses-permission android:name="android.permission.ACCESS_WIFI_STATE"/&gt;
      &lt;uses-permission android:name="android.permission.PERSISTENT_ACTIVITY"/&gt;
      &lt;uses-permission android:name="android.permission.HARDWARE_TEST"/&gt;
      &lt;uses-permission android:name="android.permission.KILL_BACKGROUND_PROCESSES"/&gt;
  
      &lt;application 
          android:icon="@drawable/ic_launcher"
          android:label="@string/mod_name" 
          android:name=".MyApp"&gt;
  
          &lt;!-- We declare our service here --&gt;
          &lt;service 
              android:enabled="true" 
              android:exported="true"
              android:icon="@drawable/ic_launcher"
              android:label="@string/serv_name" 
              android:name=".MyApp" 
              android:process=":my_process"&gt;
              &lt;intent-filter&gt;
                &lt;action android:name="com.company.package.MY_INTENT" /&gt;
              &lt;/intent-filter&gt;
              &lt;/service&gt;
          &lt;receiver 
              android:name=".ControlReceiver"&gt;
              &lt;intent-filter&gt;
                  &lt;action android:name="android.intent.action.BOOT_COMPLETED"/&gt;
                  &lt;action android:name="android.intent.action.ACTION_EXTERNAL_APPLICATIONS_AVAILABLE" /&gt;
              &lt;/intent-filter&gt;
          &lt;/receiver&gt;
          &lt;receiver 
              android:name=".BatteryHelper" &gt;
              &lt;intent-filter&gt;
                  &lt;action android:name="android.intent.action.BATTERY_OKAY"/&gt;
                  &lt;action android:name="android.intent.action.BATTERY_CHANGED"/&gt;
                  &lt;action android:name="android.intent.action.ACTION_POWER_DISCONNECTED"/&gt;
                  &lt;action android:name="android.intent.action.ACTION_POWER_CONNECTED"/&gt;
                  &lt;action android:name="android.intent.action.BATTERY_LOW"/&gt;
                  &lt;category android:name="android.intent.category.INFO"/&gt;
              &lt;/intent-filter&gt;
          &lt;/receiver&gt;
      &lt;/application&gt;
  &lt;/manifest&gt;
  </code></pre>
  
  <p>The exception thrown</p>
  
  <pre><code>FATAL EXCEPTION: main 
  java.lang.RuntimeException: Unable to instantiate application com.company.package.MyApp: java.lang.ClassCastException: com.company.package.MyApp cannot be cast to android.app.Application    
   at android.app.LoadedApk.makeApplication(LoadedApk.java:529)    
   at android.app.ActivityThread.handleBindApplication(ActivityThread.java:4442)     
   at android.app.ActivityThread.access$1300(ActivityThread.java:139)     
   at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1305)     
   at android.os.Handler.dispatchMessage(Handler.java:99)     
   at android.os.Looper.loop(Looper.java:154)     
   at android.app.ActivityThread.main(ActivityThread.java:4945)    
   at java.lang.reflect.Method.invokeNative(Native Method)     
   at java.lang.reflect.Method.invoke(Method.java:511) 
  </code></pre>
  
  <p><strong>Update</strong><br/>
  When I removed android:name=".MyApp" for the application from the manifest, the service started. Anyone know why?</p>