title: java.lang.NullPointerException...int java.lang.CharSequence.length()' on a null object reference
body: <p>I have been getting this error since I implemented the</p>
  <pre><code>public void getOtherAnimals(){
              DatabaseReference otherAnimalDb = FirebaseDatabase.getInstance().getReference().child(&quot;Users&quot;).child(animalTwo);
              otherAnimalDb.addChildEventListener(new ChildEventListener() {
                  @Override
                  public void onChildAdded(DataSnapshot snapshot, String s) {
                      if (snapshot.exists() &amp;&amp; !snapshot.child(&quot;connections&quot;).child(&quot;no&quot;).hasChild(currentUId) &amp;&amp; !snapshot.child(&quot;connections&quot;).child(&quot;yes&quot;).hasChild(currentUId)){
                          Cards item = new Cards(snapshot.getKey(), snapshot.child(&quot;name&quot;).getValue().toString());
                          rowItems.add(item);
                          arrayAdapter.notifyDataSetChanged();
                      }
                  }
  </code></pre>
  <p>section of code, the program worked beautifully before.  I have done my reading on NullPointerExceptions but I don't have enough experience working with them to find the issue. I understand my program is pointing to a null object, but I cannot find it.</p>
  <pre><code>E/AndroidRuntime: FATAL EXCEPTION: main
  Process: com.example.android.adoptme, PID: 20525
  java.lang.NullPointerException: Attempt to invoke interface method 'int java.lang.CharSequence.length()' on a null object reference
      at java.util.regex.Matcher.reset(Matcher.java:177)
      at java.util.regex.Matcher.&lt;init&gt;(Matcher.java:90)
      at java.util.regex.Pattern.matcher(Pattern.java:297)
      at com.google.firebase.database.core.utilities.Validation.isValidPathString(Validation.java:40)
      at com.google.firebase.database.core.utilities.Validation.validatePathString(Validation.java:44)
      at com.google.firebase.database.DataSnapshot.hasChild(DataSnapshot.java:80)
      at com.example.android.adoptme.MainActivity$5.onChildAdded(MainActivity.java:186)
      at com.google.firebase.database.core.ChildEventRegistration.fireEvent(ChildEventRegistration.java:79)
      at com.google.firebase.database.core.view.DataEvent.fire(DataEvent.java:63)
      at com.google.firebase.database.core.view.EventRaiser$1.run(EventRaiser.java:55)
      at android.os.Handler.handleCallback(Handler.java:739)
      at android.os.Handler.dispatchMessage(Handler.java:95)
      at android.os.Looper.loop(Looper.java:135)
      at android.app.ActivityThread.main(ActivityThread.java:5254)
      at java.lang.reflect.Method.invoke(Native Method)
      at java.lang.reflect.Method.invoke(Method.java:372)
      at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:903)
      at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:698)
  </code></pre>
  <p>Here is my code: (And yes I am aware that there is probably a better way to write it, I am still working on it and refining it with research).</p>
  <pre><code>package com.example.android.adoptme;
  
  import androidx.annotation.NonNull;
  import androidx.annotation.Nullable;
  import androidx.appcompat.app.AppCompatActivity;
  import androidx.appcompat.widget.FitWindowsViewGroup;
  
  import android.content.Context;
  import android.content.Intent;
  import android.os.Bundle;
  import android.util.Log;
  import android.view.View;
  import android.widget.ArrayAdapter;
  import android.widget.Button;
  import android.widget.ListView;
  import android.widget.Toast;
  
  import com.google.firebase.auth.FirebaseAuth;
  import com.google.firebase.auth.FirebaseUser;
  import com.google.firebase.database.ChildEventListener;
  import com.google.firebase.database.DataSnapshot;
  import com.google.firebase.database.DatabaseError;
  import com.google.firebase.database.DatabaseReference;
  import com.google.firebase.database.FirebaseDatabase;
  import com.lorentzos.flingswipe.SwipeFlingAdapterView;
  
  import java.util.ArrayList;
  import java.util.List;
  
  public class MainActivity extends AppCompatActivity {
  
  
          private Cards cards_data[];
          private arrayAdapter arrayAdapter;
          private int i;
  
          private FirebaseAuth firebaseAuth;
  
          private String currentUId;
  
          private DatabaseReference petDb;
  
          ListView listView;
          List&lt;Cards&gt; rowItems;
  
          @Override
          protected void onCreate(Bundle savedInstanceState) {
              super.onCreate(savedInstanceState);
              setContentView(R.layout.activity_main);
  
              petDb = FirebaseDatabase.getInstance().getReference().child(&quot;Users&quot;);
  
              firebaseAuth = FirebaseAuth.getInstance();
  
              checkAnimalType();
  
              rowItems = new ArrayList&lt;Cards&gt;();
              arrayAdapter = new arrayAdapter(this, R.layout.item, rowItems);
  
              SwipeFlingAdapterView flingContainer = (SwipeFlingAdapterView) findViewById(R.id.frame);
  
  
              flingContainer.setAdapter(arrayAdapter);
              flingContainer.setFlingListener(new SwipeFlingAdapterView.onFlingListener() {
                  @Override
                  public void removeFirstObjectInAdapter() {
                      // this is the simplest way to delete an object from the Adapter (/AdapterView)
                      Log.d(&quot;LIST&quot;, &quot;removed object!&quot;);
                      rowItems.remove(0);
                      arrayAdapter.notifyDataSetChanged();
                  }
  
                  @Override
                  public void onLeftCardExit(Object dataObject) {
                      Cards obj = (Cards) dataObject;
                      String userId = obj.getUserId();
                      petDb.child(userId).child(userId).child(&quot;connections&quot;).child(&quot;no&quot;).child(currentUId).setValue(true);
  
                      makeToast(MainActivity.this, &quot;Left!&quot;);
                  }
  
                  @Override
                  public void onRightCardExit(Object dataObject) {
                      Cards obj = (Cards) dataObject;
                      String userId = obj.getUserId();
                      petDb.child(userId).child(userId).child(&quot;connections&quot;).child(&quot;yes&quot;).child(currentUId).setValue(true);
  
                      makeToast(MainActivity.this, &quot;Right!&quot;);
  
  
                  }
  
                  @Override
                  public void onAdapterAboutToEmpty(int itemsInAdapter) {
                  }
  
                  @Override
                  public void onScroll(float scrollProgressPercent) {
  
                  }
              });
  
  
              // Optionally add an OnItemClickListener
              flingContainer.setOnItemClickListener(new SwipeFlingAdapterView.OnItemClickListener() {
                  @Override
                  public void onItemClicked(int itemPosition, Object dataObject) {
                      makeToast(MainActivity.this, &quot;Clicked!&quot;);
                  }
              });
  
          }
  
          static void makeToast(Context ctx, String s){
              Toast.makeText(ctx, s, Toast.LENGTH_SHORT).show();
          }
  
          private String animalOne, animalTwo;
          public void checkAnimalType(){
  
              final FirebaseUser user = FirebaseAuth.getInstance().getCurrentUser();
  
              DatabaseReference dogDb = FirebaseDatabase.getInstance().getReference().child(&quot;Users&quot;).child(&quot;Dog&quot;);
              dogDb.addChildEventListener(new ChildEventListener() {
                  @Override
                  public void onChildAdded( DataSnapshot snapshot, String s) {
                      if (snapshot.getKey().equals(user.getUid())){
                          animalOne = &quot;Dog&quot;;
                          animalTwo = &quot;Cat&quot;;
                          getOtherAnimals();
                      }
                  }
  
                  @Override
                  public void onChildChanged(DataSnapshot snapshot, String s) {
                  }
  
                  @Override
                  public void onChildRemoved(DataSnapshot snapshot) {
                  }
  
                  @Override
                  public void onChildMoved(DataSnapshot snapshot, String s) {
                  }
  
                  @Override
                  public void onCancelled(DatabaseError error) {
                  }
              });
  
  
              DatabaseReference catDb = FirebaseDatabase.getInstance().getReference().child(&quot;Users&quot;).child(&quot;Cat&quot;);
              catDb.addChildEventListener(new ChildEventListener() {
                  @Override
                  public void onChildAdded(DataSnapshot snapshot, String s) {
                      if (snapshot.getKey().equals(user.getUid())){
                          animalOne = &quot;Cat&quot;;
                          animalTwo = &quot;Dog&quot;;
                          getOtherAnimals();
                      }
                  }
  
                  @Override
                  public void onChildChanged(DataSnapshot snapshot, String s) {
                  }
  
                  @Override
                  public void onChildRemoved( DataSnapshot snapshot) {
                  }
  
                  @Override
                  public void onChildMoved(DataSnapshot snapshot, String s) {
                  }
  
                  @Override
                  public void onCancelled(DatabaseError error) {
                  }
              });
          }
  
          public void getOtherAnimals(){
              DatabaseReference otherAnimalDb = FirebaseDatabase.getInstance().getReference().child(&quot;Users&quot;).child(animalTwo);
              otherAnimalDb.addChildEventListener(new ChildEventListener() {
                  @Override
                  public void onChildAdded(DataSnapshot snapshot, String s) {
                      if (snapshot.exists() &amp;&amp; !snapshot.child(&quot;connections&quot;).child(&quot;no&quot;).hasChild(currentUId) &amp;&amp; !snapshot.child(&quot;connections&quot;).child(&quot;yes&quot;).hasChild(currentUId)){
                          Cards item = new Cards(snapshot.getKey(), snapshot.child(&quot;name&quot;).getValue().toString());
                          rowItems.add(item);
                          arrayAdapter.notifyDataSetChanged();
                      }
                  }
  
                  @Override
                  public void onChildChanged(DataSnapshot snapshot, String s) {
                  }
  
                  @Override
                  public void onChildRemoved(DataSnapshot snapshot) {
                  }
  
                  @Override
                  public void onChildMoved(DataSnapshot snapshot, String s) {
                  }
  
                  @Override
                  public void onCancelled(DatabaseError error) {
                  }
              });
          }
  
          public void logoutUser (View view){
              firebaseAuth.signOut();
              Intent intent = new Intent (MainActivity.this, LoginRegistration.class);
              startActivity(intent);
          }
      }
  </code></pre>
  <p>I appreciate any help you can provide me. Thanks in advance.</p>