gpt4 book ai didi

java - Android 开机接收器崩溃

转载 作者:行者123 更新时间:2023-11-29 21:50:06 28 4
gpt4 key购买 nike

我的手机已连接到 Eclipse,但我无法看到 logcat,直到手机“完全”启动并且我的接收器(应用程序)在此之前崩溃,所以我无法调试它。我确定它必须根据上下文和 Intent 做一些事情:

我确定由于上下文问题,我的接收器在启动时崩溃了:

 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

最佳答案

你应该只使用上下文,用上下文替换上下文,你应该没问题。

关于java - Android 开机接收器崩溃,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/14662980/

28 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com