find many solutions but not solve my problem where I am going to wrong please anyone correct me. I am a beginner to set an Alarm in the application.
public void setAlarm(String alarmTime) {
//Toast.makeText(getActivity(), "set Alarm", Toast.LENGTH_LONG).show();
Date date = null;
try {`enter code here`
SimpleDateFormat formatter = new SimpleDateFormat("hh:mm:ss a");
date = (Date) formatter.parse(alarmTime);
} catch (Exception e) {
e.printStackTrace();
}
Intent intent = new Intent(getActivity(), AlarmAlert.class);//problem here getActivity()
AlarmManager alarmManager = (AlarmManager) getActivity().getSystemService(Context.ALARM_SERVICE);
PendingIntent pendingIntent = PendingIntent.getBroadcast(getContext(), 0, intent, 0);
assert date != null;
alarmManager.setExact(AlarmManager.RTC_WAKEUP, date.getTime(), pendingIntent);
Toast.makeText(getActivity(), "Set Alarm", Toast.LENGTH_SHORT).show();
}