title: Why am I getting null reference error for spinner here?
body: <p>I am programming in android studio and here is my code snippet :</p>
  
  <pre><code>public class settingsView extends Fragment {
  
      public settingsView() {
      }
  
      @Nullable
      @Override
      public View onCreateView(@NonNull LayoutInflater inflater, @Nullable ViewGroup container, @Nullable Bundle savedInstanceState) {
  
          final Spinner citySpinner = (Spinner) getActivity().findViewById(R.id.citySpinner);
  
          FirebaseDatabase.getInstance().getReference("/movies/karnataka").addValueEventListener(new ValueEventListener() {
              @Override
              public void onDataChange(@NonNull DataSnapshot dataSnapshot) {
  
                  ArrayList&lt;String&gt; cityList = new ArrayList&lt;&gt;();
  
                  for (DataSnapshot snapshot : dataSnapshot.getChildren()) {
                      cityList.add(snapshot.getKey());
                  }
  
                  Log.d("firebasedata", cityList.toString());
  
                  ArrayAdapter&lt;String&gt; adapter = new ArrayAdapter&lt;String&gt;(getActivity().getApplicationContext(), android.R.layout.simple_spinner_item, cityList );
                  adapter.setDropDownViewResource(android.R.layout.simple_spinner_item);
                  citySpinner.setAdapter(adapter);
              }
  
              @Override
              public void onCancelled(@NonNull DatabaseError databaseError) {
              }
          });
  
  
          return inflater.inflate(R.layout.settingsview, container, false);
      }
  }
  </code></pre>
  
  <p>I am getting </p>
  
  <pre><code>java.lang.NullPointerException: Attempt to invoke virtual method 'void android.widget.Spinner.setAdapter(android.widget.SpinnerAdapter) on a null object reference exception 
  </code></pre>
  
  <p>at line :</p>
  
  <p><code>citySpinner.setAdapter(adapter)</code></p>