title: Spinner with Firebase on Fragment
body: <p>I want to create spinner with firebase, but when I'm running and click the spinner, the application is error and this is the message :</p>
  <p><strong>java.lang.NullPointerException: Attempt to invoke virtual method 'java.lang.String java.lang.Object.toString()' on a null object reference</strong></p>
  <p>this my code in Fragment</p>
  <pre><code> spinner = view.findViewById(R.id.spinner);
          names = new ArrayList&lt;&gt;();
          databaseReference = FirebaseDatabase.getInstance().getReference();
          databaseReference.child(&quot;spinners&quot;).addValueEventListener(new ValueEventListener() {
              @Override
              public void onDataChange(@NonNull DataSnapshot snapshot) {
  
                  for (DataSnapshot chilSnap:snapshot.getChildren()) {
                      String spinnerName = chilSnap.child(&quot;name&quot;).getValue(String.class);
                      names.add(spinnerName);
                      if (spinnerName!=null){
                          names.add(spinnerName);
                      }
                  }
                  ArrayAdapter&lt;String&gt; arrayAdapter= new ArrayAdapter&lt;&gt;(getActivity(), android.R.layout.simple_spinner_item, names);
                  arrayAdapter.setDropDownViewResource(android.R.layout.simple_dropdown_item_1line);
                  spinner.setAdapter(arrayAdapter);
              }
  
              @Override
              public void onCancelled(@NonNull DatabaseError error) {
  
              }
          });
  </code></pre>