尝试调用未调用的BroadcastReceiver时出现NullPointerException

时间:2014-08-17 02:47:04

标签: android service broadcastreceiver alarmmanager android-pendingintent

出于某种原因,我得到NullPointerException。我已经完成了关于这个问题的所有帖子。我想知道我在这里失踪了什么。

我打算调用一个服务,该服务将触发一个警报管理器来激活应该在特定时间(而不是持续时间)调用的延迟意图。

活动代码,调用服务

    autoBookingIntent = new Intent(this,
            ScheduleAdvanceBookingService.class);        
    autoBookingIntent.putExtra("startTime", startTime);
    autoBookingIntent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
    startService(autoBookingIntent) ;

清单

     <service
        android:name="com.taxeeta.ScheduleAdvanceBookingService"
        android:enabled="true"
        android:label="@string/app_name"
        android:theme="@android:style/Theme.Light.NoTitleBar" />

ScheduleAdvanceBookingService代码

此处有例外 ==&gt;

package com.taxeeta;

public ScheduleAdvanceBookingService() {
    super("ScheduleAdvanceBookingService");
}

@Override
protected void onHandleIntent(Intent intent) {
    Intent newIntent = new Intent(this, AutoAdvanceBooking.class);
    **==>**newIntent.putExtra("sourceLng",
            intent.getDoubleExtra("sourceLng", (Double) null));
    Date startTime = (Date) intent.getSerializableExtra("startTime");
    newIntent.putExtra("startTime", startTime);
    autoBookingAlarm = (AlarmManager) this
            .getSystemService(Context.ALARM_SERVICE);
    autoBookingPendingIntent = PendingIntent.getBroadcast(this, 0,
            newIntent, PendingIntent.FLAG_UPDATE_CURRENT);
    autoBookingAlarm.set(AlarmManager.RTC_WAKEUP, startTime.getTime(),
            autoBookingPendingIntent);

    God.setAdvanceBookingNotification(this, God.CREATE_NOTIFICATION,
            startTime);
}

为什么意图为null?

1 个答案:

答案 0 :(得分:0)

我想哭,这对我来说是一个愚蠢的错误。

newIntent.putExtra("sourceLng",
            intent.getDoubleExtra("sourceLng", (Double) null));

这会产生NULLPOINTEREXCEPTION