알람 시계에 불이 켜져 있고 알람을 일시 중지해야하는 pendingIntent가 있습니다. 동일한 코드는 활동에있을 때 훌륭하게 작동했습니다. 나는 어떤 것들을 바꾼다. 그리고 지금은 다른 것을 바꾼다. 나는 nullpointerExecption을 얻는다. (계약자 활동의 컨텍스트를 얻는다클래스에서 호출하려고 할 때 PendingIntent null
스누즈 기능 :.
public void settingNewIntentForSnooze() {
PendingIntent alarmPendingIntent=null;
Calendar calendar = Calendar.getInstance();
// new alarm after the snooze.
calendar.set(Calendar.MINUTE, calendar.get(Calendar.MINUTE) + snoozeTime);
Intent snoozeIntent = new Intent(context, Alarm_Reciver.class);
snoozeIntent.putExtra("click_status", true);
//add that to try to solve the problem...
snoozeIntent.setAction("Snooze");
alarmPendingIntent = PendingIntent.getBroadcast(context, 0, snoozeIntent, alarmPendingIntent.FLAG_ONE_SHOT);
//tells to phone to set the alarm
alarm_manager.set(AlarmManager.RTC_WAKEUP, calendar.getTimeInMillis(), alarmPendingIntent);
}
AlarmPage 활동 (가변을지지하는 코드)
snooze= new Snooze(this,alarm_manager);
AlarmReciver :
public void onReceive(Context context, Intent intent) {
Log.e("in alarm reciver","in alarm reciver");
Intent service_intent= new Intent(context, RingtonePlayingService.class);//intent for the service ringtone playing
boolean button_status = intent.getExtras().getBoolean("click_status");
service_intent.putExtra("click_status", button_status);//passing button status
context.startService(service_intent);//start the ringtone service
}
오류 :
09-17 18:25:25.564 1563-1563/com.example.itay.newfrindlyalarm E/AndroidRuntime: FATAL EXCEPTION: main
Process: com.example.itay.newfrindlyalarm, PID: 1563
java.lang.NullPointerException: Attempt to invoke virtual method 'void android.app.AlarmManager.set(int, long, android.app.PendingIntent)' on a null object reference
at com.example.itay.newfrindlyalarm.Snooze.settingNewIntentForSnooze(Snooze.java:60)
at com.example.itay.newfrindlyalarm.Snooze.operate(Snooze.java:44)
at com.example.itay.newfrindlyalarm.AlarmPage.operateSnooze(AlarmPage.java:88)
at com.example.itay.newfrindlyalarm.AlarmPage$3.onClick(AlarmPage.java:68)
at android.view.View.performClick(View.java:6256)
at android.view.View$PerformClick.run(View.java:24697)
at android.os.Handler.handleCallback(Handler.java:789)
at android.os.Handler.dispatchMessage(Handler.java:98)
at android.os.Looper.loop(Looper.java:164)
at android.app.ActivityThread.main(ActivityThread.java:6541)
at java.lang.reflect.Method.invoke(Native Method)
at com.android.internal.os.Zygote$MethodAndArgsCaller.run(Zygote.java:240)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:767)
enter code here
첫 번째 줄에'alarmPendingInten = null'을 정의하는 이유는 무엇입니까?하지만'getBroadcast'를 canl 할 때 나중에 재정의합니까? 그게 나쁜 스타일이다 :) –
'settingNewIntentForSnooze' 메소드의'context' 값은 무엇입니까? 그것은 좋은 가치가 있습니까? –
오류 메시지를 추가하십시오. 오류를 보지 않고 코드를 디버그하는 것은 어렵습니다. –