我的手机已连接到 Eclipse,但在手机“完全”启动之前我看不到 logcat,并且我的接收器(应用程序)在此之前崩溃,所以我无法调试它。我确信它必须与上下文和意图有关:
由于上下文问题,我的接收器在启动时崩溃了,我敢肯定:
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());
}
}
更新,终于设法捕捉到异常:
01-06 02:21:19.920: E/AndroidRuntime(7360): java.lang.RuntimeException: Unable to start receiver com.example.prva.OnBootReceiver: java.lang.NullPointerException