嘿,所以我一直在创建一个在用户指定的时间发送每周通知的应用程序。
我已经按照了大量的教程,似乎一遍又一遍地阅读同样的内容,我似乎无法让它发挥作用。当我调用新意图时,我的应用程序崩溃了。难道我做错了什么?这是完成这项任务的正确方法吗?
public class AlarmService extends Activity
{
/// unimportant working code not added
Intent mintent = new Intent(context, mBroadcastReceiver.class);
Log.d(TAG, "Got Intent");
/// I receive a log just before this portion but do not receive this one
startActivity(PAintent);
Log.d(TAG, "StartActivity(intent)");
PendingIntent mPendingIntent = PendingIntent.getActivity(getApplicationContext(), ALARMID,
mintent, PendingIntent.FLAG_CANCEL_CURRENT);
Log.d(TAG, "Got Pending intent");
AlarmManager mAlarm = (AlarmManager) getSystemService(ALARM_SERVICE);
Log.d(TAG, "Got alarmmanager");
///// remember to change time back to: (7 * 24 * 60 * 60 * 1000)
mAlarm.setRepeating(AlarmManager.RTC_WAKEUP,
ALARM_TIME.getTimeInMillis(), (30 * 1000),
mPendingIntent);
Log.d(TAG, "Made Pending intent");
...
}
请记住,我在此代码中重命名了我的intent,pendingintent和alarm manager,以便于阅读!
我一直收到空指针异常,我的调试看起来像这样:
03-05 13:20:45.132: E/AndroidRuntime(12734): FATAL EXCEPTION: main
03-05 13:20:45.132: E/AndroidRuntime(12734): java.lang.NullPointerException
03-05 13:20:45.132: E/AndroidRuntime(12734): at android.content.ComponentName.<init>(ComponentName.java:75)
03-05 13:20:45.132: E/AndroidRuntime(12734): at android.content.Intent.<init>(Intent.java:2720)
03-05 13:20:45.132: E/AndroidRuntime(12734): at com.theStudyBuddy.Ignite.AlarmService.PlannerAssistantOn(AlarmService.java:148)
03-05 13:20:45.132: E/AndroidRuntime(12734): at com.theStudyBuddy.Ignite.EditScheduleActivity.saveClass(EditScheduleActivity.java:635)
03-05 13:20:45.132: E/AndroidRuntime(12734): at com.theStudyBuddy.Ignite.EditScheduleActivity.onClick(EditScheduleActivity.java:583)
03-05 13:20:45.132: E/AndroidRuntime(12734): at android.view.View.performClick(View.java:2485)
......等等
如果有人能指出我的错误,将非常感谢!
答案 0 :(得分:1)
startActivity(PAintent); PAintent在哪里?你创造它吗?
要启动预定活动:您可以看到以下链接: Android : AlarmManager not start