title: Why when I want to access this fragment my application fails? Android Studio
body: <p>I am developing an application in which I want to insert data in firebase, but when I want to open the fragment in the application I get an error.
  I am using nav_graph for navigation between screens and I am also using movile_navigation. I don't know if that is information that could be important.</p>
  <p>This is the java code, I don't know what causes the error:</p>
  <pre><code>```
      
          public class Pantalla1Fragment extends Fragment{
      TextView editTextName;
      TextView editTextEdad;
      TextView editTextApellidos;
      TextView editTextGenero;
      TextView editPadecimientos;
      TextView editTextObservaciones;
      TextView getEditTextTratamientos;
      Button btnRegistar;
  
      FirebaseAuth mAuth;
      DatabaseReference mDatabase;
  
      // TODO: Rename parameter arguments, choose names that match
      // the fragment initialization parameters, e.g. ARG_ITEM_NUMBER
      private static final String ARG_PARAM1 = &quot;param1&quot;;
      private static final String ARG_PARAM2 = &quot;param2&quot;;
  
      // TODO: Rename and change types of parameters
      private String mParam1;
      private String mParam2;
  
      public Pantalla1Fragment() {
          // Required empty public constructor
      }
  
      /**
       * Use this factory method to create a new instance of
       * this fragment using the provided parameters.
       *
       * @param param1 Parameter 1.
       * @param param2 Parameter 2.
       * @return A new instance of fragment Pantalla1Fragment.
       */
      // TODO: Rename and change types and number of parameters
      public static Pantalla1Fragment newInstance(String param1, String param2) {
          Pantalla1Fragment fragment = new Pantalla1Fragment();
          Bundle args = new Bundle();
          args.putString(ARG_PARAM1, param1);
          args.putString(ARG_PARAM2, param2);
          fragment.setArguments(args);
          return fragment;
      }
  
      /*@Override
      public void onCreate(Bundle savedInstanceState) {
          super.onCreate(savedInstanceState);
  
          if (getArguments() != null) {
              mParam1 = getArguments().getString(ARG_PARAM1);
              mParam2 = getArguments().getString(ARG_PARAM2);
          }
      }*/
  
     @Override
      public View onCreateView(LayoutInflater inflater, ViewGroup container,
                               Bundle savedInstanceState) {
          // Inflate the layout for this fragment
          return inflater.inflate(R.layout.fragment_pantalla1, container, false);
      }
  
      @Override
      public void onViewCreated(@NonNull View view, Bundle savedInstanceState) {
          super.onViewCreated(view, savedInstanceState);
  
          if (getArguments() != null) {
              mParam1 = getArguments().getString(ARG_PARAM1);
              mParam2 = getArguments().getString(ARG_PARAM2);
          }
          editTextName = view.findViewById(R.id.editTextName);
          editTextEdad = view.findViewById(R.id.editTextEdad);
          editTextApellidos = view.findViewById(R.id.editTextApellidos);
          editTextGenero = view.findViewById(R.id.editTextGenero);
          editPadecimientos = view.findViewById(R.id.editTextPadesimientos);
          editTextObservaciones = view.findViewById(R.id.editTextObservaciones);
          getEditTextTratamientos = view.findViewById(R.id.editTextTratamientos);
  
          btnRegistar = view.findViewById(R.id.btnRegistar);
  
  
  
          btnRegistar.setOnClickListener(new View.OnClickListener() {
              @Override
              public void onClick(View v) {
                  registerPerfil();
              }
          });
      }
  
      public void registerPerfil() {
          String nombre=editTextName.getText().toString();
          String apellidos=editTextApellidos.getText().toString();
          String edad=editTextEdad.getText().toString();
          String genero=editTextGenero.getText().toString();
          String padecimientos=editPadecimientos.getText().toString();
          String tratamiento=getEditTextTratamientos.getText().toString();
          String observaciones=editTextObservaciones.getText().toString();
  
          if(!TextUtils.isEmpty(nombre)){
              String id=mDatabase.push().getKey();
              Registro_Perfiles perfil = new Registro_Perfiles(nombre, apellidos, edad, genero, padecimientos, tratamiento, observaciones);
  
              mDatabase.child(&quot;Users&quot;).child(id).setValue(perfil);
              //Toast.makeText(this, &quot;Datos introducidos&quot;, Toast.LENGTH_LONG).show();
          }
      }
  }
  </code></pre>
  <pre><code>And this part is the fragment view:
  
     &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;.Pantalla1Fragment&quot;&gt;
     
     &lt;ScrollView
         android:layout_width=&quot;match_parent&quot;
         android:layout_height=&quot;match_parent&quot;
         app:layout_constraintBottom_toBottomOf=&quot;parent&quot;
         app:layout_constraintEnd_toEndOf=&quot;parent&quot;
         app:layout_constraintStart_toStartOf=&quot;parent&quot;
         android:padding=&quot;15dp&quot;
         app:layout_constraintTop_toTopOf=&quot;parent&quot;&gt;
     
         &lt;LinearLayout
             android:layout_width=&quot;match_parent&quot;
             android:layout_height=&quot;match_parent&quot;
             android:orientation=&quot;vertical&quot;&gt;
     
             &lt;TextView
                 android:layout_width=&quot;wrap_content&quot;
                 android:layout_height=&quot;wrap_content&quot;
                 android:text=&quot;Nombre&quot; /&gt;
     
             &lt;EditText
                 android:id=&quot;@+id/editTextName&quot;
                 android:layout_width=&quot;match_parent&quot;
                 android:layout_height=&quot;wrap_content&quot;
                 android:layout_marginTop=&quot;10dp&quot;
                 android:hint=&quot;@string/editTextNombre&quot; /&gt;
     
             &lt;TextView
                 android:layout_width=&quot;wrap_content&quot;
                 android:layout_height=&quot;wrap_content&quot;
                 android:layout_marginTop=&quot;10dp&quot;
                 android:text=&quot;Apellidos&quot; /&gt;
     
             &lt;EditText
                 android:id=&quot;@+id/editTextApellidos&quot;
                 android:layout_width=&quot;match_parent&quot;
                 android:layout_height=&quot;wrap_content&quot;
                 android:layout_marginTop=&quot;10dp&quot;
                 android:hint=&quot;Apellidos&quot; /&gt;
     
             &lt;TextView
                 android:layout_width=&quot;wrap_content&quot;
                 android:layout_height=&quot;wrap_content&quot;
                 android:layout_marginTop=&quot;10dp&quot;
                 android:text=&quot;Edad&quot; /&gt;
     
             &lt;EditText
                 android:id=&quot;@+id/editTextEdad&quot;
                 android:layout_width=&quot;match_parent&quot;
                 android:layout_height=&quot;wrap_content&quot;
                 android:layout_marginTop=&quot;10dp&quot;
                 android:hint=&quot;Edad&quot; /&gt;
     
             &lt;TextView
                 android:layout_width=&quot;wrap_content&quot;
                 android:layout_height=&quot;wrap_content&quot;
                 android:layout_marginTop=&quot;10dp&quot;
                 android:text=&quot;Genero&quot; /&gt;
     
             &lt;EditText
                 android:id=&quot;@+id/editTextGenero&quot;
                 android:layout_width=&quot;match_parent&quot;
                 android:layout_height=&quot;wrap_content&quot;
                 android:layout_marginTop=&quot;10dp&quot;
                 android:hint=&quot;Genero&quot; /&gt;
     
             &lt;TextView
                 android:layout_width=&quot;wrap_content&quot;
                 android:layout_height=&quot;wrap_content&quot;
                 android:layout_marginTop=&quot;10dp&quot;
                 android:text=&quot;Padesimientos&quot; /&gt;
     
             &lt;EditText
                 android:id=&quot;@+id/editTextPadesimientos&quot;
                 android:layout_width=&quot;match_parent&quot;
                 android:layout_height=&quot;wrap_content&quot;
                 android:layout_marginTop=&quot;10dp&quot;
                 android:hint=&quot;Padesimientos&quot; /&gt;
     
             &lt;TextView
                 android:layout_width=&quot;wrap_content&quot;
                 android:layout_height=&quot;wrap_content&quot;
                 android:layout_marginTop=&quot;10dp&quot;
                 android:text=&quot;Tratamientos&quot; /&gt;
     
             &lt;EditText
                 android:id=&quot;@+id/editTextTratamientos&quot;
                 android:layout_width=&quot;match_parent&quot;
                 android:layout_height=&quot;wrap_content&quot;
                 android:layout_marginTop=&quot;10dp&quot;
                 android:hint=&quot;Tratamientos&quot; /&gt;
     
             &lt;TextView
                 android:layout_width=&quot;wrap_content&quot;
                 android:layout_height=&quot;wrap_content&quot;
                 android:layout_marginTop=&quot;10dp&quot;
                 android:text=&quot;Observaciones&quot; /&gt;
     
             &lt;EditText
                 android:id=&quot;@+id/editTextObservaciones&quot;
                 android:layout_width=&quot;match_parent&quot;
                 android:layout_height=&quot;wrap_content&quot;
                 android:layout_marginTop=&quot;10dp&quot;
                 android:hint=&quot;Observaciones&quot; /&gt;
     
             &lt;Button
                 android:id=&quot;@+id/btnRegistar&quot;
                 android:layout_width=&quot;wrap_content&quot;
                 android:layout_height=&quot;wrap_content&quot;
                 android:layout_marginTop=&quot;10dp&quot;
                 android:text=&quot;REGISTRAR NUEVO PERFIL&quot; /&gt;
     
         &lt;/LinearLayout&gt;
     &lt;/ScrollView&gt;
     
     &lt;/androidx.constraintlayout.widget.ConstraintLayout&gt;
  </code></pre>
  <p>Error in the logcat</p>
  <pre><code>    --------- beginning of crash
  2020-08-26 12:13:05.893 17635-17635/com.example.thebestapp E/AndroidRuntime: FATAL EXCEPTION: main
      Process: com.example.thebestapp, PID: 17635
      java.lang.NullPointerException: Attempt to invoke virtual method 'com.google.firebase.database.DatabaseReference com.google.firebase.database.DatabaseReference.push()' on a null object reference
          at com.example.thebestapp.Pantalla1Fragment.registerPerfil(Pantalla1Fragment.java:126)
          at com.example.thebestapp.Pantalla1Fragment$1.onClick(Pantalla1Fragment.java:111)
          at android.view.View.performClick(View.java:6297)
          at android.view.View$PerformClick.run(View.java:24797)
          at android.os.Handler.handleCallback(Handler.java:790)
          at android.os.Handler.dispatchMessage(Handler.java:99)
          at android.os.Looper.loop(Looper.java:164)
          at android.app.ActivityThread.main(ActivityThread.java:6626)
          at java.lang.reflect.Method.invoke(Native Method)
          at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:438)
          at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:811)
  </code></pre>