【问题标题】:NullPointerException when trying to call BroadcastReceiver not called尝试调用未调用的 BroadcastReceiver 时出现 NullPointerException
【发布时间】:2014-08-17 02:47:03
【问题描述】:

由于某种原因,我收到了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 代码

此处例外==>

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);
}

为什么intent为空?

【问题讨论】:

    标签: android service broadcastreceiver alarmmanager android-pendingintent


    【解决方案1】:

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

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

    这会产生NULLPOINTEREXCEPTION

    【讨论】:

      猜你喜欢
      • 2012-08-02
      • 2013-01-05
      • 1970-01-01
      • 2013-12-29
      • 2015-02-13
      • 2012-01-21
      • 2012-08-29
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多