title: WakefulBroadcastReceiver get java.lang.ClassNotFoundException
body: <p>In my Android project, I have a <code>Service</code> class:</p>
  
  <pre><code>public class MyService extends Service{
     ...
  
     //Defined a WakefulBroadcastReceiver as a inner static class
     public static class DeviceRebootReceiver extends WakefulBroadcastReceiver {
  
      @Override
      public void onReceive(Context context, Intent intent) {
                //Do something when user reboot the device
          }
    }
  
  }
  </code></pre>
  
  <p>As you see above, I have defined a <code>WakefulBroadcastReceiver</code> as a <strong>inner static class</strong> in <code>MyService</code> class. This receiver receives the broadcast when user reboot his/her device.</p>
  
  <p>My AndroidManifest.xml looks like this:</p>
  
  <pre><code>&lt;?xml version="1.0" encoding="utf-8"?&gt;
  &lt;manifest xmlns:android="http://schemas.android.com/apk/res/android"
      package="com.my.project"
      android:versionCode="1"
      android:versionName="2.1" &gt;
  
     &lt;uses-permission android:name="android.permission.INTERNET" /&gt;
     &lt;uses-permission android:name="android.permission.WAKE_LOCK" /&gt;
     &lt;uses-permission android:name="android.permission.RECEIVE_BOOT_COMPLETED" /&gt;
  
     &lt;application
       ...&gt;
        &lt;activity ...&gt; ... &lt;/activity&gt;
  
        &lt;service android:name="com.my.project.MyService"
                 android:exported="false"/&gt;
  
         &lt;receiver
              android:name="com.my.project.MyService$DeviceRebootReceiver"
            &gt;
              &lt;intent-filter&gt;
                  &lt;action android:name="android.intent.action.BOOT_COMPLETED" /&gt;
              &lt;/intent-filter&gt;
          &lt;/receiver&gt;
     &lt;/application&gt;
  &lt;/manifest&gt;
  </code></pre>
  
  <p>But when I run my app &amp; after rebooted the device, my logcat shows me error:</p>
  
  <pre><code>Unable to instantiate receiver com.my.project.MyService$DeviceRebootReceiver: 
  java.lang.ClassNotFoundException:  com.my.project.MyService$DeviceRebootReceiver in loader dalvik.system.PathClassLoader[/data/app/com.my.project-1.apk]
  </code></pre>
  
  <p>Why my receiver class is not able to be loaded by system?</p>
  
  <p><strong>=====Update======</strong></p>
  
  <p>I also tried to make my <code>DeviceRebootReceiver</code> as a <strong>separate</strong> class (<em>DeviceRebootReceiver.java</em>), and made the <code>AndroidManifest.xml</code> changed to :</p>
  
  <pre><code> &lt;application...&gt;
      &lt;receiver
        android:name="com.my.project.DeviceRebootReceiver"
            &gt;
             &lt;intent-filter&gt;
                 &lt;action android:name="android.intent.action.BOOT_COMPLETED" /&gt;
             &lt;/intent-filter&gt;
       &lt;/receiver&gt;
  &lt;/application&gt;
  </code></pre>
  
  <p>But I still get the similar error in logcat:</p>
  
  <pre><code>java.lang.RuntimeException: Unable to instantiate receiver com.my.project.DeviceRebootReceiver: java.lang.ClassNotFoundException
  </code></pre>