title: layout is not showing when broadcast receiver is sending message
body: <p>I have a dashboard activity which have 3 fragment ,initially it is calling a home fragment, I want to show a layout when my I receive a broadcast of Internet is not connected but my layout is always showing null pointer exception...at first the visibility of  internet layout is gone.</p>
  <p>when I set my visibility on then it is showing and overlapping my fragment design but as soon as set its visibility gone and then want to show it always show error</p>
  <p>why this happening</p>
  <p>checkNet.java</p>
  <pre><code>
   DashBoardActivity dashBoardActivity = new DashBoardActivity();
  
      public void onReceive(Context context, Intent intent) {
          try {
              if (isOnline(context)) {
                 dashBoardActivity.checkNet(true);
                  Log.e(&quot;checkInternet&quot;, &quot;App is back to Online  &quot;);
  
              } else {
  
                  dashBoardActivity.checkNet(false);
                  Log.e(&quot;checkInternet&quot;, &quot;Conectivity Failure  !!! &quot;);
              }
          } catch (NullPointerException e) {
              e.printStackTrace();
          }
      }
  
  
      private boolean isOnline(Context context) {
  
          try {
              ConnectivityManager cm = (ConnectivityManager) context.getSystemService(Context.CONNECTIVITY_SERVICE);
              NetworkInfo netInfo = cm.getActiveNetworkInfo();
              
              return (netInfo != null &amp;&amp; netInfo.isConnected());
          } catch (NullPointerException e) {
              e.printStackTrace();
              return false;
          }
  
      }
  }
  
  
  
  </code></pre>
  <p>this function is in dashboard acitvity</p>
  <pre><code>
     public  void checkNet(boolean value) {
  
          if (value) {
              Log.e(&quot;Connected&quot;, &quot;Yes &quot;);
               
          }
          else {
              Log.e(&quot;Connected&quot;, &quot;NO &quot;);
              something_wrong_LL.setVisibility(View.VISIBLE);
             
  }
  
             
  
  
  </code></pre>
  <p>dashboard.xml</p>
  <pre><code>&lt;?xml version=&quot;1.0&quot; encoding=&quot;utf-8&quot;?&gt;
  &lt;androidx.constraintlayout.widget.ConstraintLayout xmlns:android=&quot;http://schemas.android.com/apk/res/android&quot;
      xmlns:app=&quot;http://schemas.android.com/apk/res-auto&quot;
      xmlns:tools=&quot;http://schemas.android.com/tools&quot;
      android:layout_width=&quot;match_parent&quot;
      android:layout_height=&quot;match_parent&quot;
      tools:context=&quot;DashBoardActivity&quot;&gt;
  
  
  
  
  
              &lt;LinearLayout
                  android:id=&quot;@+id/something_wrong_LL&quot;
                  android:layout_width=&quot;match_parent&quot;
                  android:layout_height=&quot;match_parent&quot;
                  android:orientation=&quot;vertical&quot;
                  android:gravity=&quot;center&quot;
                  android:visibility=&quot;gone&quot;
                  app:layout_constraintBottom_toTopOf=&quot;@+id/card1&quot;
                  app:layout_constraintEnd_toEndOf=&quot;parent&quot;
                  app:layout_constraintStart_toStartOf=&quot;parent&quot;
                  app:layout_constraintTop_toTopOf=&quot;parent&quot; &gt;
  
  
                  &lt;TextView
                      android:layout_width=&quot;wrap_content&quot;
                      android:layout_height=&quot;wrap_content&quot;
                      android:fontFamily=&quot;@font/nunito&quot;
                      android:text=&quot;somethingWrong&quot;
                      android:textColor=&quot;@color/gray_2&quot;/&gt;
  
                  &lt;Button
                      android:id=&quot;@+id/retry_BT&quot;
                      android:layout_marginTop=&quot;20dp&quot;
                      android:layout_width=&quot;wrap_content&quot;
                      android:layout_height=&quot;35dp&quot;
                      android:text=&quot;RETRY&quot;
                      android:background=&quot;@drawable/blue_background_bg&quot;
                      android:textColor=&quot;@color/whiteColor&quot;/&gt;
  
              &lt;/LinearLayout&gt;
  
  
  
  
  
  
      &lt;FrameLayout
          android:id=&quot;@+id/content_frame&quot;
          android:layout_width=&quot;0dp&quot;
          android:layout_height=&quot;0dp&quot;
          android:visibility=&quot;visible&quot;
          app:layout_constraintBottom_toTopOf=&quot;@+id/card1&quot;
          app:layout_constraintEnd_toEndOf=&quot;parent&quot;
          app:layout_constraintStart_toStartOf=&quot;parent&quot;
          app:layout_constraintTop_toTopOf=&quot;parent&quot;/&gt;
  
  
      &lt;com.google.android.material.card.MaterialCardView
          android:id=&quot;@+id/card1&quot;
          android:layout_width=&quot;0dp&quot;
          app:contentPadding=&quot;0dp&quot;
          android:layout_height=&quot;?attr/actionBarSize&quot;
          android:layout_alignParentBottom=&quot;true&quot;
          android:theme=&quot;@style/Theme.MaterialComponents.Light.NoActionBar&quot;
          app:cardElevation=&quot;16dp&quot;
          app:cardPreventCornerOverlap=&quot;false&quot;
          app:layout_constraintBottom_toBottomOf=&quot;parent&quot;
          app:layout_constraintEnd_toEndOf=&quot;parent&quot;
          app:layout_constraintStart_toStartOf=&quot;parent&quot;&gt;
  
  
  
         .
         .
         .
         .
         .
         .
         .
          
      &lt;/com.google.android.material.card.MaterialCardView&gt;
  
  
  &lt;/androidx.constraintlayout.widget.ConstraintLayout&gt;
  
  
  
  
  </code></pre>