title: App crashes upon clicking button in Fragment to show TimePickerDialog
body: <p>I'm trying to display a TimePickerDialog in a Fragment. When the button is clicked, the TimePickerDialog does not appear and the app crashes. There is a class cast issue stated in the logcat.</p>
  
  <p>AlarmFragment class:</p>
  
  <pre><code>public class AlarmFragment extends Fragment implements TimePickerDialog.OnTimeSetListener {
      @Nullable
      @Override
      public View onCreateView(LayoutInflater inflater, @Nullable ViewGroup container, @Nullable Bundle savedInstanceState) {
          View alarmView = inflater.inflate(R.layout.fragment_alarm, container, false);
  
          Button button = (Button) alarmView.findViewById(R.id.end_button);
          button.setOnClickListener(new View.OnClickListener() {
              @Override
              public void onClick(View v) {
                  DialogFragment timePicker = new TimePickerFragment();
                  timePicker.show(getActivity().getSupportFragmentManager(), "time picker");
              }
          });
  
          return alarmView;
      }
  
      @Override
      public void onTimeSet(TimePicker view, int hourOfDay, int minute) {
  
          TextView textView = (TextView) getActivity().findViewById(R.id.time_textView);
          textView.setText("Hour: " + hourOfDay + " Minute: " + minute);
      }
  
  }
  </code></pre>
  
  <p>TimePickerFragment class:</p>
  
  <pre><code>public class TimePickerFragment extends DialogFragment {
      @NonNull
      @Override
      public Dialog onCreateDialog(Bundle savedInstanceState) {
          Calendar c = Calendar.getInstance();
          int hour = c.get(Calendar.HOUR_OF_DAY);
          int minute = c.get(Calendar.MINUTE);
  
          TimePickerDialog timePickerDialog = new TimePickerDialog(getActivity(), (TimePickerDialog.OnTimeSetListener) getActivity(), hour, minute, DateFormat.is24HourFormat(getActivity()));
          return timePickerDialog;
      }
  }
  </code></pre>
  
  <p>Error Message in logcat:</p>
  
  <pre><code>2019-07-22 18:07:49.104 4872-4872/mapp.com.sg.thesleepingsheep E/AndroidRuntime: FATAL EXCEPTION: main
      Process: mapp.com.sg.thesleepingsheep, PID: 4872
      java.lang.ClassCastException: mapp.com.sg.thesleepingsheep.MainActivity cannot be cast to android.app.TimePickerDialog$OnTimeSetListener
          at mapp.com.sg.thesleepingsheep.TimePickerFragment.onCreateDialog(TimePickerFragment.java:21)
          at android.support.v4.app.DialogFragment.onGetLayoutInflater(DialogFragment.java:330)
          at android.support.v4.app.Fragment.performGetLayoutInflater(Fragment.java:1308)
          at android.support.v4.app.FragmentManagerImpl.moveToState(FragmentManager.java:1460)
          at android.support.v4.app.FragmentManagerImpl.moveFragmentToExpectedState(FragmentManager.java:1784)
          at android.support.v4.app.FragmentManagerImpl.moveToState(FragmentManager.java:1852)
          at android.support.v4.app.BackStackRecord.executeOps(BackStackRecord.java:802)
          at android.support.v4.app.FragmentManagerImpl.executeOps(FragmentManager.java:2625)
          at android.support.v4.app.FragmentManagerImpl.executeOpsTogether(FragmentManager.java:2411)
          at android.support.v4.app.FragmentManagerImpl.removeRedundantOperationsAndExecute(FragmentManager.java:2366)
          at android.support.v4.app.FragmentManagerImpl.execPendingActions(FragmentManager.java:2273)
          at android.support.v4.app.FragmentManagerImpl$1.run(FragmentManager.java:733)
          at android.os.Handler.handleCallback(Handler.java:751)
          at android.os.Handler.dispatchMessage(Handler.java:95)
          at android.os.Looper.loop(Looper.java:154)
          at android.app.ActivityThread.main(ActivityThread.java:6119)
          at java.lang.reflect.Method.invoke(Native Method)
          at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:886)
          at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:776)
  </code></pre>