title: Android, setOnClickLister Error, I don't see what's wrong
body: <p>I keep getting the following error:</p>
  
  <pre><code> java.lang.NullPointerException: Attempt to invoke virtual method 'void android.widget.ScrollView.setVisibility(int)' on a null object reference
  </code></pre>
  
  <p>When button is clicked, I want scrollView and it's contents to hide.</p>
  
  <p>But I don't see what's wrong. I connected my button to scrollView but it doesn't work. Here's my code for button in fragment:</p>
  
  <pre><code> public class SavedBroad extends Fragment {
  
  Button activityButtonPhoto;
  public ScrollView broadScroll;
  
  
  Button activityButtonBroad;
  public ScrollView photoScroll;
  
  View rootView;
  
  
  @Override
  public View onCreateView(LayoutInflater inflater, ViewGroup container,
                           Bundle savedInstanceState) {
       rootView = inflater.inflate(R.layout.activity_saved_broad_tabbar, container, false);
  
  
       broadScroll = rootView.findViewById(R.id.BroadScrollView); 
     // photoScroll = rootView.findViewById(R.id.PhotoScrollView);  
  
  
    //  broadScroll= getActivity().findViewById(R.id.BroadScrollView); 
    // photoScroll=getActivity().findViewById(R.id.PhotoScrollView);
  
  
  
  
      activityButtonPhoto= rootView.findViewById(R.id.PhotoVid);
      activityButtonPhoto.setOnClickListener(new View.OnClickListener() {
          @Override
          public void onClick(View view) {
  
  
              broadScroll.setVisibility(View.INVISIBLE);
  
          }
  
      });
  
      return rootView;
  
      }
  
  
     } 
  </code></pre>
  
  <p>Here's my XML file:</p>
  
  <pre><code>&lt;Button
      android:id="@+id/PhotoVid"
      android:layout_width="wrap_content"
      android:layout_height="wrap_content"
      android:layout_marginEnd="8dp"
      android:layout_marginLeft="8dp"
      android:layout_marginRight="8dp"
      android:layout_marginStart="8dp"
      android:layout_marginTop="6dp"
      android:background="@android:color/holo_green_dark"
      android:text="PhotoVid"
      app:layout_constraintHorizontal_bias="0.155"
      app:layout_constraintLeft_toLeftOf="parent"
      app:layout_constraintRight_toRightOf="parent"
      app:layout_constraintTop_toTopOf="parent" /&gt;
  
  &lt;Button
  
      android:id="@+id/broad"
      android:layout_width="wrap_content"
      android:layout_height="wrap_content"
      android:layout_marginEnd="8dp"
      android:layout_marginLeft="8dp"
      android:layout_marginRight="8dp"
      android:layout_marginStart="8dp"
      android:layout_marginTop="6dp"
      android:background="@android:color/holo_red_dark"
      android:text="Broadcast"
      app:layout_constraintHorizontal_bias="0.741"
      app:layout_constraintLeft_toLeftOf="parent"
      app:layout_constraintRight_toRightOf="parent"
      app:layout_constraintTop_toTopOf="parent" /&gt;
  
  &lt;ScrollView
      android:id="@+id/BroadScrollView"
      android:layout_width="393dp"
      android:layout_height="505dp"
      android:layout_marginBottom="144dp"
      android:layout_marginEnd="8dp"
      android:layout_marginLeft="8dp"
      android:layout_marginRight="8dp"
      android:layout_marginStart="8dp"
      android:layout_marginTop="8dp"
      android:background="@android:color/holo_red_dark"
      app:layout_constraintBottom_toBottomOf="parent"
      app:layout_constraintLeft_toLeftOf="parent"
      app:layout_constraintRight_toRightOf="parent"
      app:layout_constraintTop_toBottomOf="@+id/broad"
      app:layout_constraintVertical_bias="0.0"&gt;
  
      &lt;LinearLayout
          android:id="@+id/BroadLayout"
          android:layout_width="match_parent"
          android:layout_height="wrap_content"
          android:orientation="vertical" /&gt;
  &lt;/ScrollView&gt;
  
  &lt;ScrollView
      android:id="@+id/PhotoScrollView"
      android:layout_width="0dp"
      android:layout_height="433dp"
      android:layout_marginLeft="8dp"
      android:layout_marginRight="8dp"
      android:background="@android:color/holo_green_dark"
      app:layout_constraintBottom_toBottomOf="@+id/BroadScrollView"
      app:layout_constraintHorizontal_bias="0.0"
      app:layout_constraintLeft_toLeftOf="parent"
      app:layout_constraintRight_toRightOf="parent"
      android:layout_marginTop="8dp"
      app:layout_constraintVertical_bias="1.0"
      app:layout_constraintTop_toBottomOf="@+id/broad"
      android:layout_marginStart="8dp"
      android:layout_marginEnd="8dp"&gt;
  
      &lt;LinearLayout
          android:id="@+id/PhotoVidLayout"
          android:layout_width="match_parent"
          android:layout_height="wrap_content"
          android:orientation="vertical" /&gt;
  &lt;/ScrollView&gt;
  </code></pre>
  
  <p>I don't understand why the button to hide ScrollView is giving me issue.</p>