title: AlarmManager.AlarmClockinfo.getNextAlarmClock() causes NullPointerException
body: <h2>The Problem</h2>
  
  <p>When I try to use the <code>AlarmManager.AlarmClockInfo</code> object to <code>getNextAlarmClock()</code> my app throws: <strong><code>Attempt to invoke virtual method 'long android.app.AlarmManager$AlarmClockInfo.getNextAlarmClock()' on a null object reference</code></strong></p>
  
  <h2>My Code</h2>
  
  <p>The relevant section of my code...</p>
  
  <pre><code>public class MyAppWidget extends AppWidgetProvider {
  
      private PendingIntent my_svc = null;
  
      public void onUpdate(Context c, AppWidgetManager awm, int[] appWidgetIds) {
  
          final AlarmManager m = (AlarmManager)c.getSystemService(Context.ALARM_SERVICE);
          final Calendar alarm_time = Calendar.getInstance();
          final Intent i = new Intent(c, MyService.class);
  
          // set alarm for 2015-Jul-7 10:35:55 AM
          alarm_time.setStime(new Date(2015,7,7,10,35,55));
  
          // set up the service if necessary
          if ( my_svc == null ) {
              my_svc = PendingIntent.getService(c, 0, i, PendingIntent.FLAG_CANCEL_CURRENT);
          }
  
          // set the alarm
          m.setExact(AlarmManager.RTC, alarm_time.getTime().getTime(), my_service);
  
          // now write a log message to confirm the alarm was set
          // **THIS IS THE CODE THAT THROWS THE EXCEPTION**
          AlarmManager.AlarmClockInfo aci = m.getNextAlarmClock();
          Log.v("MyAppWidget", "next alarm at: " + aci.toString());
      }
  }
  </code></pre>
  
  <h2>Background Info</h2>
  
  <p>I'm developing a home/lock screen widget app for Android. The info in the widget needs to be updated at very specific times other than when the OS broadcasts the <code>APPWIDGET_UPDATE</code> action. I successfully followed <a href="http://www.parallelrealities.co.uk/2011/09/using-alarmmanager-for-updating-android.html" rel="nofollow noreferrer">this tutorial on using <code>AlarmManager</code> to update widgets at specific times</a>, and was able to use the <code>AlarmManager.setRepeating()</code> function to update my widget once a minute.</p>
  
  <p>However, I don't need the widget updated every minute, but only once at a specific time that happens every 2-3 days. So I tried using <code>AlarmManager.setExact()</code> instead of <code>setRepeating()</code>. The app compiles without error and appears to run just fine, but the widget doesn't update when I think it is supposed to. I've confirmed that the correct time is being submitted to the <code>setExact()</code> function, but since the update doesn't happen as scheduled I wanted to see whether or not the alarm was really set. That's when I tried using <code>getNextAlarmClock()</code> and began having these problems.</p>
  
  <h2>App/Emulator Specs</h2>
  
  <p>App:</p>
  
  <ul>
  <li>minSdkVersion: 21</li>
  <li>targetSdkVersion: 22</li>
  </ul>
  
  <p>Emulator:</p>
  
  <ul>
  <li>Name: Nexus 5 API 22</li>
  <li>CPU/ABI: Google API's Intel Atom (x86)</li>
  <li>Target: Google APIs (API level 22)</li>
  <li>SD Card: 100M</li>
  <li>GPU Enabled: yes</li>
  <li>RAM Size: 2GB</li>
  </ul>
  
  <h2>Things I've tried</h2>
  
  <ul>
  <li>Logging <code>alarm_time.getTime().toString</code> to confirm I'm setting the correct alarm time</li>
  <li>Confirmed that the time of the alarm is in the future (by manually setting the time on the emulator)</li>
  <li><a href="https://stackoverflow.com/questions/27333972/next-alarm-formatted-is-deprecated">Solutions suggested by this SO thread</a></li>
  <li>Variations on <code>getNextAlarmClock()</code> including using the deprecated constant, <code>getTriggerTime()</code> and <code>m.getNextAlarmClock().toString()</code></li>
  </ul>
  
  <p>I'm totally stumped by this. If you have any thoughts about why I can't get info about the next set alarm, or why my alarm set with <code>setExact()</code> doesn't go off, I'll be a happy boy. Thank you!!!</p>