Note that there are some explanatory texts on larger screens.

plurals
  1. POBoot Receiver causing app to stop
    primarykey
    data
    text
    <p>I have a boot reciever in my homework planner application to re-set all of the alarms that are created to remind the user of their homework being due in. Everytime my phone boots, I get "Homework planner has stopped", and I cannot figure out why. And I cannot use LogCat as it is not connecting on startup (?).</p> <p>This is my code in the boot reciever.</p> <pre><code>public class BootReceiver extends BroadcastReceiver { @Override public void onReceive(Context context, Intent intent) { // RE-SET ALL ALARMS FROM THE DATABASE WHEN PHONE IS TURNED ON HomeworkDatabase db = new HomeworkDatabase(context); db.open(); ArrayList&lt;HomeworkItem&gt; hwks = db.getHomeworks(); db.close(); int reminders = 0; for (int e = 0; e &lt; hwks.size(); e++) { HomeworkItem current = hwks.get(e); { Calendar c = Calendar.getInstance(); c.set(current.year, current.month, current.day, 0, 0); long alarmTime = c.getTimeInMillis(); Intent i = new Intent(HomeworkList.getAppContext(), RegularAlarm.class); i.putExtra("title", current.title); i.putExtra("id", current.id); PendingIntent pi = PendingIntent.getBroadcast( HomeworkList.getAppContext(), (int) current.id, i, 0); AlarmManager mAlarm = (AlarmManager) context .getApplicationContext().getSystemService( Context.ALARM_SERVICE); mAlarm.set(AlarmManager.RTC_WAKEUP, alarmTime, pi); reminders++; } if (current.oneDayReminder == true) { Calendar c = Calendar.getInstance(); c.set(current.year, current.month, current.day, 0, 0); c.roll(Calendar.DAY_OF_MONTH, -1); long alarmTime = c.getTimeInMillis(); Intent i = new Intent(HomeworkList.getAppContext(), OneDayAlarm.class); i.putExtra("title", current.title); i.putExtra("id", current.id); PendingIntent pi = PendingIntent.getBroadcast( HomeworkList.getAppContext(), (int) current.id, i, 0); AlarmManager mAlarm = (AlarmManager) context .getApplicationContext().getSystemService( Context.ALARM_SERVICE); mAlarm.set(AlarmManager.RTC_WAKEUP, alarmTime, pi); reminders++; } if (current.twoDayReminder == true) { Calendar c = Calendar.getInstance(); c.set(current.year, current.month, current.day, 0, 0); c.roll(Calendar.DAY_OF_MONTH, -2); long alarmTime = c.getTimeInMillis(); Intent i = new Intent(HomeworkList.getAppContext(), TwoDaysAlarm.class); i.putExtra("title", current.title); i.putExtra("id", current.id); PendingIntent pi = PendingIntent.getBroadcast( HomeworkList.getAppContext(), (int) current.id, i, 0); AlarmManager mAlarm = (AlarmManager) context .getApplicationContext().getSystemService( Context.ALARM_SERVICE); mAlarm.set(AlarmManager.RTC_WAKEUP, alarmTime, pi); reminders++; } } Log.d("hwk","BOOT COMPLETE: " + reminders + " alarms created"); Toast.makeText(context, reminders + " alarms created at boot", Toast.LENGTH_LONG); } } </code></pre> <p>Sorry for the long code snippet, but I have no idea what the problem is.</p> <p>Thanks</p> <p>EDIT: The source of the error is when creating the intent and getting the context from the for the PendingIntent.</p> <pre><code>Intent i = new Intent(HomeworkList.getAppContext(), RegularAlarm.class); </code></pre> <p>This line is causing a null pointer exception. Any idea why?</p>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload