title: java.lang.NullPointerException at java.util.Objects.requireNonNull
body: <p>In my code, I am calling a a function <code>addFood</code> as follows from an activity</p>
  
  <pre><code>postFood f = new postFood();
  f.addFood(context, breakfastDate, breakfastSearch, 1);
  </code></pre>
  
  <p>and then the code runs the following code</p>
  
  <pre><code>public class postFood extends DialogFragment {
      @SuppressLint("StaticFieldLeak")
      private static Context context1;
      @SuppressLint("StaticFieldLeak")
      private static ListView dateList1, selectedList1;
      private static ProgressDialog progressDialog;
      private static int mealType1;
      private static String TAG = "AddSelectedFood";
      private static String date;
      private static String time;
      public static String[] dateTimeString;
      public static Calendar cal;
  
  
      public  void addFood(Context context, ListView dateList, ListView selectedList,
                             int mealType) {
          dateList1 = dateList;
          selectedList1 = selectedList;
          context1 = context;
          mealType1 = mealType;
          //*FragmentManager manager = Objects.requireNonNull(this.getActivity()).getSupportFragmentManager();
  
          // Use the current date as the default date in the picker
          new datePickerFragment().show(Objects.requireNonNull(getActivity()).getSupportFragmentManager(), "datePicker");
      }
  }
  </code></pre>
  
  <p>What can I do in order to prevent getActivity().getSuppotFragmentManaget from being null?</p>
  
  <p>here is my LOG</p>
  
  <pre><code>2019-01-15 12:08:37.898 7908-7908/com.example.khali.nutriplan E/AndroidRuntime: FATAL EXCEPTION: main
  Process: com.example.khali.nutriplan, PID: 7908
  java.lang.NullPointerException
      at java.util.Objects.requireNonNull(Objects.java:203)
      at com.example.khali.nutriplan.postFood.addFood(postFood.java:63)
      at com.example.khali.nutriplan.breakfastPage$1.onClick(breakfastPage.java:114)
      at android.view.View.performClick(View.java:6597)
      at android.view.View.performClickInternal(View.java:6574)
      at android.view.View.access$3100(View.java:778)
      at android.view.View$PerformClick.run(View.java:25885)
      at android.os.Handler.handleCallback(Handler.java:873)
      at android.os.Handler.dispatchMessage(Handler.java:99)
      at android.os.Looper.loop(Looper.java:193)
      at android.app.ActivityThread.main(ActivityThread.java:6669)
      at java.lang.reflect.Method.invoke(Native Method)
      at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:493)
      at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:858)
  </code></pre>