title: Alarm clock app using AlarmManager crashes
body: <p>There are no errors but it keeps closing unexpectedly when i try to run it on my phone or an emulator.</p>
  
  <p>here my main activity which calls the broadcast receiver to set the alarm off.</p>
  
  <pre><code>@Override
  protected void onCreate(Bundle savedInstanceState) {
      super.onCreate(savedInstanceState);
      setContentView(R.layout.activity_main);
       DatePicker datePicker = (DatePicker)findViewById(R.id.datePicker);
          TimePicker timePicker = (TimePicker)findViewById(R.id.timePicker);
          Button btnset = (Button)findViewById(R.id.button1);
          Button btncancel = (Button)findViewById(R.id.button2);
  
          btnset.setOnClickListener(this); 
          btncancel.setOnClickListener(this);
  
  
  }
          public void onClick (View v) {
  
          switch( v.getId()) {
  
          case R.id.button1:
  
              Calendar calendar= Calendar.getInstance();
              calendar.set(Calendar.MONTH, datePicker.getMonth());
              calendar.set(Calendar.DAY_OF_MONTH, datePicker.getDayOfMonth());
              calendar.set(Calendar.YEAR, datePicker.getYear());
              calendar.set(Calendar.HOUR_OF_DAY, timePicker.getCurrentHour());
              calendar.set(Calendar.MINUTE, timePicker.getCurrentMinute());
  
  
  
  
          Intent AlarmIntent = new Intent(MainActivity.this, AlarmReceiver.class);
          AlarmManager AlmMgr = (AlarmManager)getSystemService(ALARM_SERVICE);
          PendingIntent Sender = PendingIntent.getBroadcast(MainActivity.this, 0, AlarmIntent, 0);    
          AlmMgr.set(AlarmManager.RTC_WAKEUP, calendar.getTimeInMillis(), Sender);
          }
  }
  </code></pre>
  
  <p>This is the broadcast receiver class: </p>
  
  <pre><code>public class AlarmReceiver extends BroadcastReceiver {
  
  
      @Override
      public void onReceive(Context context, Intent intent) 
      {   //Build pending intent from calling information to display Notification
          PendingIntent Sender = PendingIntent.getBroadcast(context, 0, intent, 0);
          NotificationManager manager = (NotificationManager)context.getSystemService(android.content.Context.NOTIFICATION_SERVICE);
          Notification noti = new Notification(android.R.drawable.stat_notify_more, "Wake up alarm", System.currentTimeMillis());
          noti.setLatestEventInfo(context, "My Alarm", "WAKE UP...!!!", Sender);
          noti.flags = Notification.FLAG_AUTO_CANCEL;
          manager.notify(R.string.app_name, noti); 
  
          /* intent to call the activity which shows on ringing
          Intent myIntent = new Intent(context, Alarmring.class);
          myIntent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
          context.startActivity(myIntent); */
  
          //display that alarm is ringing
          Toast.makeText(context, "Alarm Ringing...!!!", Toast.LENGTH_LONG).show();
      }}
  </code></pre>
  
  <p>I am also adding the log error</p>
  
  <pre><code>03-12 13:11:33.160: E/AndroidRuntime(10625): FATAL EXCEPTION: main 
  03-12 13:11:33.160: E/AndroidRuntime(10625): java.lang.NullPointerException 
  03-12 13:11:33.160: E/AndroidRuntime(10625): at com.example.myexample.MainActivity.onClick(MainActivity.java:44) 
  03-12 13:11:33.160: E/AndroidRuntime(10625): at android.view.View.performClick(View.java:2532) 
  03-12 13:11:33.160: E/AndroidRuntime(10625): at android.view.View$PerformClick.run(View.java:9277) 
  03-12 13:11:33.160: E/AndroidRuntime(10625): at android.os.Handler.handleCallback(Handler.java:587)
  </code></pre>