2017-03-18 14 views
1

안녕하세요, 나는 스위치를 사용하여 알람을 해제하고 SQL 데이터베이스에서 특정 알람 ID를 얻으려고하고 있습니다. 현재 비활성화하려고 할 때마다 null 참조가 수신됩니다. 나는 지금도 그 일을하고 있지만 누군가가 빠른 시각을 가질 수 있다면 그것은 위대 할 것입니다. 목록보기 어댑터에 알람을 만들기스위치를 사용하여 알람 취소

final int id = (int) System.currentTimeMillis(); 

pendingIntent = PendingIntent.getBroadcast(v.getContext(), id, receiver, PendingIntent.FLAG_UPDATE_CURRENT); 

alarmManager.set(AlarmManager.RTC_WAKEUP, myCalendar.getTimeInMillis(), pendingIntent); 

intentArrayList.add(pendingIntent); 

BaseAdapter에서 데이터베이스를 취소 나의 시도.

mySwitch.setOnCheckedChangeListener(new CompoundButton.OnCheckedChangeListener() { 

@Override 
public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) { 

cursor.moveToPosition(position); 

if (mySwitch.isChecked()){ 

Toast.makeText(view.getContext(), Integer.toString(position) + "ENABLED", Toast.LENGTH_SHORT).show(); 

} else { 

String id = cursor.getString(cursor.getColumnIndexOrThrow("alarm_code")); 

pendingIntent = PendingIntent.getBroadcast(view.getContext(), Integer.valueOf(id), receiver, PendingIntent.FLAG_UPDATE_CURRENT); 

alarmManager.cancel(pendingIntent); 

Toast.makeText(view.getContext(), "DISABLED", Toast.LENGTH_SHORT).show(); 

      } 

현재의 에러 메시지 ..... 널 객체 참조를 '무효 android.content.Intent.prepareToLeaveProcess (android.content.Context)'의 가상 메소드를 호출

시도

답변

0

이 두 줄을 넣는 것을 잊지 않으면 오류를 수정했습니다.

alarmManager = (AlarmManager) view.getContext().getSystemService(Context.ALARM_SERVICE); 
receiver = new Intent(view.getContext(), Alarm_Reciever.class);