title: App stopped working error whenever device is rebooted and alarms are to be reset
body: <p>I am creating an Android app which will include an alarm. Whenever the device is rebooted, I want to reset the alarms again. In order to do so I am using a broadcast receiver to receive the boot completed action and then reset the alarm. However when I run the application and then reboot the device, I get an error message saying my app has stopped working. </p>
  
  <p>Can anyone tell me why this occurs? Thanks</p>
  
  <p><strong>Broadcast Receiver code:</strong></p>
  
  <pre><code>public class BootReceiver extends BroadcastReceiver
  {
  
     @Override
     public void onReceive(Context context, Intent intent)
     {
  
        Calendar cal = Calendar.getInstance();
        cal.set(Calendar.HOUR_OF_DAY,21);
        cal.set(Calendar.MINUTE,50);
  
        if (intent.getAction().equalsIgnoreCase("android.intent.action.BOOT_COMPLETED"))
        {
           Toast.makeText(context, "Alarm has been reset for " + cal.getTime().toString(), Toast.LENGTH_SHORT).show();
           // Set the alarm here.
           Intent resetAlarm = new Intent(context, AlarmReceiver.class);
           PendingIntent pendingIntent = PendingIntent.getBroadcast(context, 1234, resetAlarm, 0);
           AlarmManager alarm = (AlarmManager) context.getSystemService(context.ALARM_SERVICE);
           alarm.setRepeating(AlarmManager.RTC_WAKEUP, cal.getTimeInMillis(), 2 * 60 * 1000, pendingIntent);
        }
     }
  }
  </code></pre>
  
  <p><strong>Android manifest file:</strong></p>
  
  <pre><code>        &lt;uses-permission android:name="android.permission.RECEIVE_BOOT_COMPLETED"/&gt;
  
          &lt;receiver android:name=".BootReceiver" android:enabled="true" android:exported="false"&gt;
          &lt;intent-filter&gt;
              &lt;action android:name="android.intent.action.BOOT_COMPLETED"&gt;&lt;/action&gt;
          &lt;/intent-filter&gt;
          &lt;/receiver&gt;
  </code></pre>