I have my phone connected to Eclipse but I can’t see logcat until phone is “fully” booted and my receiver (application) crashes before that so I’m unable to debug it. I’m sure it has to do something with context and intents :
My receiver is crashing on boot because of context problems I’m sure :
public void onReceive(Context context, Intent intent) {
// TODO Auto-generated method stub
Calendar c2 = Calendar.getInstance();
int hour = c2.get(Calendar.HOUR_OF_DAY);
int minute = c2.get(Calendar.MINUTE);
int sek = c2.get(Calendar.SECOND);
int dan;
int dodaj;
milivreme = ((hour * 60 * 60 * 1000)+ (minute * 60 * 1000) + (sek * 1000));
Cursor cursor = DatabaseManager.getAllData();
cursor.moveToFirst();
if (!cursor.isAfterLast())
{
do
{
milibaza = cursor.getInt(3);
razlika = milibaza - milivreme;
Intent intent1 = new Intent(context, AlarmReceiver.class);
PendingIntent pendingintent = PendingIntent.getService(context, 2, intent1, PendingIntent.FLAG_CANCEL_CURRENT);
AlarmManager am = (AlarmManager) context.getSystemService(context.ALARM_SERVICE);
am.set(AlarmManager.RTC_WAKEUP, System.currentTimeMillis() + razlika, pendingintent);
}
while (cursor.moveToNext());
}
}
Update, finally managed to catch the exception :
01-06 02:21:19.920: E/AndroidRuntime(7360): java.lang.RuntimeException: Unable to start receiver com.example.prva.OnBootReceiver: java.lang.NullPointerException
You should use
Context context, don’tContext contextic.My question for you : why did you write
while (cursor.moveToNext());(the thing is that you use semicolon after loop) ?If my answer isn’t helpful, give please stack trace.