title: Cannot resolve method 'getSupportFragmentManager' in 'NetworkChangeListener'
body: <p>I developed a class to the listener when wifi is off and I wrote an alert dialog to show a message. Now I specialized a class to show messages in every class, but I can't resolve the error.</p>
  <pre><code>    public class Messages extends AppCompatDialogFragment {
      
          private String message;
      
          public Messages(String message){
              this.message = message;
          }
      
          @NonNull
          @Override
          public Dialog onCreateDialog(@Nullable Bundle savedInstanceState) {
              AlertDialog.Builder builder = new AlertDialog.Builder(getActivity());
              builder.setTitle(&quot;Warning!!!&quot;)
                     .setMessage(this.message)
                     .setPositiveButton(&quot;ok&quot;, new DialogInterface.OnClickListener() {
                         @Override
                         public void onClick(DialogInterface dialog, int which) {
      
                         }
                     });
              return builder.create();
          }
      }
  
      public class NetworkChangeListener extends BroadcastReceiver {
  
      private static final String CONNECTION_WIFI_OFF =&quot;WIFI OFF.&quot;;
  
      @Override
      public void onReceive(Context context, Intent intent) {
        
          if(ConnectivityManager.CONNECTIVITY_ACTION.equals(intent.getAction())){
             
                  Messages messages = new Messages(CONNECTION_WIFI_OFF);
                  messages.show(getSupportFragmentManager(),&quot;messages&quot;);
              }
          }
  
      }
  }
  </code></pre>
  <p>I changed <code>messages.show(getSupportFragmentManager(),&quot;messages&quot;);</code> in <code>messages.show(messages.getChildFragmentManager(),&quot;messages&quot;);</code>, but it doesn't work. I received this error:</p>
  <pre><code>java.lang.RuntimeException: Error receiving broadcast Intent { act=android.net.conn.CONNECTIVITY_CHANGE flg=0x4000010 (has extras) } in com.example.connectivity.NetworkChangeListener@44fa736
          at android.app.LoadedApk$ReceiverDispatcher$Args.run(LoadedApk.java:891)
          at android.os.Handler.handleCallback(Handler.java:739)
          at android.os.Handler.dispatchMessage(Handler.java:95)
          at android.os.Looper.loop(Looper.java:148)
          at android.app.ActivityThread.main(ActivityThread.java:5417)
          at java.lang.reflect.Method.invoke(Native Method)
          at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:726)
          at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:616)
       Caused by: java.lang.IllegalStateException: Fragment Messages{f08eacf} (69334c8a-e786-46b5-bf7a-61a6b901b9d5) has not been attached yet.
          at androidx.fragment.app.Fragment.getChildFragmentManager(Fragment.java:1075)
          at com.example.connectivity.NetworkChangeListener.onReceive(NetworkChangeListener.java:49)
          at android.app.LoadedApk$ReceiverDispatcher$Args.run(LoadedApk.java:881)
          at android.os.Handler.handleCallback(Handler.java:739) 
          at android.os.Handler.dispatchMessage(Handler.java:95) 
          at android.os.Looper.loop(Looper.java:148) 
          at android.app.ActivityThread.main(ActivityThread.java:5417) 
          at java.lang.reflect.Method.invoke(Native Method) 
          at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:726) 
          at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:616) 
  </code></pre>